0

i m trying to include some items in the JavaScript arrays that is the id's of the li element. any suggestions.

  <html>
  <head>
  <script type="text/javscript">
   var arr=[];
   </script>
  </head>
   <body>
  <ul>
  <li id="index.html"></li>
  <li id="gallery.html" ></li>
  <li id="Contact Us.html"></li>
  </ul>
  </body>

  </html>

3 Answers 3

2
$(function() {
    var arr = $('li').map(function() {
        return this.id;
    }).get();
});
Sign up to request clarification or add additional context in comments.

Comments

1
$(function(){
    var arr = [];
    $('li').each(function(){
      arr.push(this.id);
    });
    console.log(arr);
});

Comments

0
$(document).ready(function() {
    var arr = new Array();
    $('li').each(function() {
        arr.push($(this).attr('id'));
    });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.