Why is my array not conforming to the CSS styles I have set?

I have been working on a code to create custom links based on user input, and have faced some challenges along the way.

Despite using snippets from various online sources, everything seems to be functioning correctly except for two issues:

  • The generated links are not adhering to the CSS rules
  • I am struggling to find a way to separate each link

I feel a bit stuck in my coding journey at this point. PS: If necessary, you can access the Fiddle https://jsfiddle.net/Adrienmlt/uspjLceg/4/

//SEARCH BOX INPUT
$('#go').one('click', function(){
var id=$('#id').val();

//ARRAY LIST 1
  var linkList = {
        "http://google.com/": "Test1",
        "http://google.org/": "Test2",
        "http://google.net/": "Test3",
    };
    
//LINK GENERATION FROM ARRAY
      for (var link in linkList) {
        if (linkList.hasOwnProperty(link)) {
          var a = document.createElement('a');
              linkText = document.createTextNode(linkList[link]);
a.href = link+id;
          a.appendChild(linkText) ;
        }
        
//CHECK BOX INPUT
if( $('input[name=Label2]').is(':checked') ){
window.open(document.body.appendChild(a))
} else {
document.body.appendChild(a);
}
      }

   //EVERY LINK OPENS IN A NEW WINDOW
   var links = document.links;
for (var i = 0; i < links.length; i++) {
     links[i].target = "_blank";
}
});
body {
padding-left: 20px;
}
h1{
font-size: 10px;
font-family: "roboto";
font-weight: 200;
}
h2{
font-size: 20px;
font-family: "roboto";
font-weight: 200;
}
div {
  padding-top: 3px;
  padding-right: 3px;
  padding-bottom: 5px;
  padding-left: 8px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<html>
  <head>
    <meta charset="utf-8">
    <title>Project 1</title>
    <script src="js/main.js"></script>
    <link type="text/css" rel="stylesheet" href="css/style.css">
  </head>
<body> 
<center> 

  <h1> 
   <div>
    <!--Checkboxes-->
                <input type="checkbox" id="Label2" name="Label2">
                <label for="Label2">Open every result in a new tab </label>
</div>
 <div>
<input type="text" value="" id="id"/>
<button type="button" id="go">GO</button> </div>
<div id="output"></div>
<div id="linkText"></div>
</h1>
</center>
  </body>
</html>

Answer №1

It appears that your CSS is adhering to the correct rules.. You can include the following code in your CSS:

//SEARCH BOX INPUT
$('#go').one('click', function(){
var id=$('#id').val();

//ARRAY LIST 1
  var linkList = {
        "http://google.com/": "Test1",
        "http://google.org/": "Test2",
        "http://google.net/": "Test3",
    };
    
//LINK GENERATION FROM ARRAY
      for (var link in linkList) {
        if (linkList.hasOwnProperty(link)) {
          var a = document.createElement('a');
              linkText = document.createTextNode(linkList[link]);
a.href = link+id;
          a.appendChild(linkText) ;
        }
        
//CHECKBOX INPUT
if( $('input[name=Label2]').is(':checked') ){
window.open(document.body.appendChild(a))
} else {
document.body.appendChild(a);
}
      }

   //EVERY LINK OPENS IN A NEW WINDOW
   var links = document.links;
for (var i = 0; i < links.length; i++) {
     links[i].target = "_blank";
}
});
body {
padding-left: 20px;
}
h1{
font-size: 10px;
font-family: "roboto";
font-weight: 200;
}
h2{
font-size: 20px;
font-family: "roboto";
font-weight: 200;
}
div {
  padding-top: 3px;
  padding-right: 3px;
  padding-bottom: 5px;
  padding-left: 8px;
}
a{
  display:block;
  color:red;
  text-decoration:none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<html>
  <head>
    <meta charset="utf-8">
    <title>Project 1</title>
    <script src="js/main.js"></script>
    <link type="text/css" rel="stylesheet" href="css/style.css">
  </head>
<body> 
<center> 

  <h1> 
   <div>
    <!--Checkboxes-->
                <input type="checkbox" id="Label2" name="Label2">
                <label for="Label2">Open every result in a new tab </label>
</div>
 <div>
<input type="text" value="" id="id"/>
<button type="button" id="go">GO</button> </div>
<div id="output"></div>
<div id="linkText"></div>
</h1>
</center>
  </body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing an array in handlebars template: A step-by-step guide

Recently, I encountered a challenge with passing a simple array variable to my Handlebars template. Here is an example of the array: var terms = ["1 year", "2 years"] I attempted to pass this variable to the template like so: var template = Handlebars.c ...

"Modify hyperlink attributes to enhance security and optimize user experience

$("a[href*='youtube']").attr('rel', 'prettyPhoto'); Having some trouble targeting links on a page containing "youtube" in the URL. I'm trying to set their rel attribute to "prettyPhoto" so they open in a lightbox window. ...

Utilizing the output of a callback function to execute res.render in a NodeJS application

Currently, I am utilizing oracledb for node in order to retrieve data from the database. Once the data is fetched, my goal is to transmit it to the client side using render() in express JS. Below is an example of the code structure: config.js module.expo ...

Exploring the World of Dates with Angular JS

let discoverDate = new Date('08-24-2015'); let occurDate = new Date('06-07-2018'); let discover = $filter("date")(discoverDate, "MM/dd/yyyy"); let occur = $filter("date")(occurDate, "MM/dd/yyyy"); console.log(discover); console.log(oc ...

Ways to create more space between text and images with Bootstrap 5

Is there a way to adjust the spacing between descriptive text and an image on a webpage? I've tried fixing it, but it didn't work. How can I ensure that my text is properly separated from the image? Thank you. <!DOCTYPE html> <html lang ...

Creating a clickable div using JavaScript: A step-by-step guide

paramToExternalFile = 'all'; var div = document.createElement('div'); div.style.background = '#D8D8D8'; div.innerHTML = '<a href=' + xml_list_externalFile_SNS1 + paramToExternalFile + '/' + letters + &a ...

Issue with Navbar Collapse Toggle not deactivating (following transition from bootstrap v4 beta to v4 alpha 6)

Recently, I encountered an issue with my navbar after switching to v4 alpha 6 in order to utilize the responsive utilities that this version offered. If you visit the following page: , you will see what I mean. Prior to upgrading to v4 alpha 6, all menu ...

"Key challenges arise when attempting to execute the node app.js script through the terminal due to various middleware compatibility

I'm a beginner with node.js and I've encountered an issue while trying to run my node app.js file after incorporating a new file named projects.js which contains the following JS code: exports.viewProject = function(req, res){ res.render(" ...

Show a variety of logos on the website based on the current date

I've been experimenting with displaying a unique logo on my website based on the current date (for example, showing a Christmas-themed logo during December). Here's what I have so far: <img class="logo" id="global_logo" sty ...

Tips on preventing scroll events from propagating in JavaScript?

Consider the following example: HTML: <div id="A"> <div id="B"> </div> </div> If a user hovers over element B and starts scrolling, we want to prevent the scroll event from affecting element A. How do we stop the scroll e ...

Highlight the phrase "figure x" within the paragraph to emphasize its importance

I want to emphasize figure 1, figure2, ...all the way up to figure 111. I am limited to making changes in HTML and CSS only, without using JavaScript or jQuery. Is there a different method than just inserting <strong> in the HTML? In CSS, we have : ...

Guide on restricting the character count and displaying the leftover characters using PHP with Ajax

I've been working on implementing a feature to display the remaining characters in a PHP AJAX call. I was successful using JavaScript, but I'm having trouble doing it with AJAX in PHP. Can someone provide assistance? <script type="text/javasc ...

Which combination of jquery version and jquery ui version is considered the most optimal?

I am wondering what the optimal combination of jQuery version and jQuery UI version is for my project? ...

Needing to utilize the provide() function individually for every service in RC4

In Beta, my bootstrapping code was running smoothly as shown below: bootstrap(App, [ provide(Http, { useFactory: (backend: XHRBackend, defaultOptions: RequestOptions, helperService: HelperService, authProvider: AuthProvider) => new CustomHt ...

Organize chat messages based on date using JavaScript

I came across a similar query, but it didn't resolve my issue. Check this out: How can I group items in an array based on date? My goal is to organize these chat messages by date after fetching them from the database using AJAX. The console displays ...

Troubleshooting problem with React's localStorage

In my app, I am fetching data from an API and displaying it on cards. The app has two pages: Home, where all cards are displayed, and Favorites, which shows only the cards marked as favorites (each card has a heart icon to indicate favoritism). I maintain ...

Clicking on a DIV element with the contenteditable attribute set to "true" does not automatically focus the element

Currently, I am using jQuery to dynamically add the content editable attribute to a DIV element. $('div').attr('contenteditable', 'true'); However, when I click on this newly modified DIV, it does not exhibit the focus effec ...

Dealing with interruptions in the sequence of results from a database request

Greetings! I am currently utilizing a customized base on Wordpress to organize and manage dog show results. The current setup displays the resulting array in a monolithic manner, which can be seen in the image here: https://i.sstatic.net/ka1SZ.png Howeve ...

Enabling Proper Emission of 'Change' in Custom Widgets at Dojo Practice

Picture this: there's a listener set up for the native dijit/form/Select element, ready to respond to the change event: nativeSelectWidget.on('change', lang.hitch(this, onSelectClick)); Now, I've developed my own custom widget that cl ...

Displaying NodeJS error messages directly in the main HTML file

After creating a form using NodeJs and implementing input validations that display errors when users enter incorrect values, I encountered an issue where the errors appear on a new blank page instead of within the main HTML file itself with stylish formatt ...