tags:

views:

58

answers:

4

i have a class .myclass i want to get the id of all textbox [html] who have this class.

how i can do this.

i need to do this in jquery

+2  A: 
$(function () {
    var id = [];
    $('.myclass').each(function () {
        if (this.id) {
            id.push(this.id);
        }
    });
});
Ninja Dude
Very Very thanks !
steven spielberg
+1  A: 
$('.someClass').each(function(){ // <-- This is a cycle, where we go through all elements having class="someClass"
    $(this).attr('id'); // <-- This contains id of a current element (in the cycle)
});
SaltLake
+4  A: 

Another way:

var ids = $('.class').map(function() { return this.id; }).get();

http://jsfiddle.net/X3Nd7/

It works best if you are sure that all elements have an ID attribute. If not, the array will contain undefined entries.

Reference: map(), get()

Felix Kling
+1  A: 
$(".myclass :text").each( function() { alert($(this).attr('id')); });

You may also want to consult the documentation at http://api.jquery.com/category/selectors/

Pizano