Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-27-2011, 04:47 AM   PM User | #1
questionable
Regular Coder

 
Join Date: Jun 2005
Posts: 153
Thanks: 26
Thanked 0 Times in 0 Posts
questionable is an unknown quantity at this point
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
questionable is offline   Reply With Quote
Old 11-27-2011, 05:00 AM   PM User | #2
Amphiluke
Regular Coder

 
Amphiluke's Avatar
 
Join Date: Jul 2009
Posts: 312
Thanks: 3
Thanked 89 Times in 89 Posts
Amphiluke is on a distinguished road
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
Amphiluke is offline   Reply With Quote
Old 11-27-2011, 05:34 AM   PM User | #3
questionable
Regular Coder

 
Join Date: Jun 2005
Posts: 153
Thanks: 26
Thanked 0 Times in 0 Posts
questionable is an unknown quantity at this point
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
questionable is offline   Reply With Quote
Old 11-27-2011, 05:46 AM   PM User | #4
Amphiluke
Regular Coder

 
Amphiluke's Avatar
 
Join Date: Jul 2009
Posts: 312
Thanks: 3
Thanked 89 Times in 89 Posts
Amphiluke is on a distinguished road
Sure
Code:
var ids = $(".testingdivs").map(function() { return this.id; }).get();
__________________
I am still learning English
Amphiluke is offline   Reply With Quote
Users who have thanked Amphiluke for this post:
questionable (11-28-2011)
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:25 AM.


Advertisement
Log in to turn off these ads.