tags:

views:

33

answers:

2

Hello id like to get the current element firing this event inside the event,

Ideally I need the id, selected value and class, Thanks in advance

$(document).ready(function () {

    $("#positions select").live("change", function () {

       var id = $("#category_id").val();
        //var id = this.val();
        alert(id);
        $.getJSON("/Category/GetSubCategories/" + id, function (data) {
            if (data.length > 0) {

                alert(data.length);
                var position = document.getElementById('positions');
                var tr = position.insertRow(7);
                var td1 = tr.insertCell(-1);
                var td = tr.insertCell(-1);
                var sel = document.createElement("select");
                sel.name = 'sel';
                sel.id = 'sel';
                sel.setAttribute('class', 'category');

                // $("positions select").live("change", function () {
                //});

                td.appendChild(sel);
                $.each(data, function (GetSubCatergories, category) {
                    $('#sel').append($("<option></option>").
           attr("value", category.category_id).
          text(category.name));

                });
            }

        });
    });
}); 
+4  A: 
$("#positions select").live("change", function () {
    var selectedVal = $(this).val(); 
    var id = $(this).attr('id'); // or this.id
    var class = $(this).attr('class');
    ...

is that what you mean?

Use .attr() to get or set element attributes.

To get a select field's selected value(s) use .val()

karim79
A: 

I'm not quite sure if I understand you right, but it looks like you either want to access

$(this).val(), $(this).attr('class') and $(this)[0].id

or the event target (the element you are actually clicking on) add a parameter to the closure in your handler, 'event' for instance:

$(event.target).val(), etc.

you might have to check if the event.target actually own all those propertys.

Kind Regards

--Andy

jAndy