RubbleFord
RubbleFord

Reputation: 7636

Convert something to Jquery object

$('#tags option').each(function(index, item) {
    // var i = this;
    //if (jQuery.inArray(i.value, idArray)) {
    // i.attr('disabled', 'true');
    // }
    item.attr('disabled', 'true');
});

How to I convert the item parameter into Jquery object so I can use all the nicety's like .attr?

Thanks

Upvotes: 6

Views: 23699

Answers (3)

jwl
jwl

Reputation: 10514

$(item).attr("whatever")

Jquery takes many different types of arguments, including straight up HTML elements, read the doco

Upvotes: 0

Peter
Peter

Reputation: 6362

You can just wrap it like this:

var jQueryItem = $(item);

where item is a DOM element. In fact, you'll find yourself doing this a lot in callback functions, since usually this refers to a DOM element and you'll usually want to operate on that using jQuery API calls.

Upvotes: 25

jimyi
jimyi

Reputation: 31191

$(item).attr('disabled', 'true'); should work

See: http://docs.jquery.com/Core/jQuery#elements

Upvotes: 13

Related Questions