Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2005
    Posts
    153
    Thanks
    26
    Thanked 0 Times in 0 Posts

    Finding all elements in a class

    Hello All,

    Is there a way to use jQuery to find all the elements by "id" in a class?

    Thanks

  • #2
    Regular Coder Amphiluke's Avatar
    Join Date
    Jul 2009
    Posts
    312
    Thanks
    3
    Thanked 89 Times in 89 Posts
    What class do you mean?
    If you want to find an element by id, then the most direct way to do it is use the "#" selector
    Code:
    var elementById = $("#id");
    I am still learning English

  • #3
    Regular Coder
    Join Date
    Jun 2005
    Posts
    153
    Thanks
    26
    Thanked 0 Times in 0 Posts
    Sorry right after I posted I thought maybe I was a little too vague.

    Alright let's say I have these divs:

    Code:
    <div id="test1" class="testingdivs"></div>
    <div id="test2" class="testingdivs"></div>
    <div id="test3" class="testingdivs"></div>
    What is there a way I could do....
    $(".testingdivs").attr("id").split(" ");

    or something to get an array of ["test1","test2","test3"]?

    Thanks

  • #4
    Regular Coder Amphiluke's Avatar
    Join Date
    Jul 2009
    Posts
    312
    Thanks
    3
    Thanked 89 Times in 89 Posts
    Sure
    Code:
    var ids = $(".testingdivs").map(function() { return this.id; }).get();
    I am still learning English

  • Users who have thanked Amphiluke for this post:

    questionable (11-28-2011)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •