tags:

views:

208

answers:

2

I have the following code:

$('.groupselect').livequery(function(){
    $('.groupselect').unbind().change(function(){
        _this = this;
        _id = $(_this).attr('id');
        //alert($(_this).val());
        alert($(_this).attr('id'));
    });
});

I can take the value from the element, but i cant take the value from the id attribute, it returns blank.

A: 

what does this give you?

$('.groupselect').live(function(){
    _this = this;
    _id = $(_this).attr('id');
    //alert($(_this).val());
    alert($(_this).attr('id'));
});

using jQuery's built in live keyword..maybe that will give better results?

puffpio
No, doesn't work, still returns blank.
Uffo
+1  A: 

puffpio almost had the answer. Here is an updated version:

$('.groupselect').live("change", function(){
  _this = this;
  _id = $(_this).attr('id');
  //alert($(_this).val());
  alert($(_this).attr('id'));
});

This is assuming you want the id of the select element. If you wanted the id of an individual option element you could use:

$('.groupselect').live("change", function(){
   $selected = $(":selected", this);
   id = $selected.attr("id");
   alert(id);
 });

Go here http://jsbin.com/urugo to see the first set of code in action. If you want to edit the code for the example go here http://jsbin.com/urugo/edit

T B
ThankYou soooo much, it works!
Uffo
No problem. I was editting the post to include a link and you had already accepted the answer!
T B