Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert something to Jquery object

Tags:

jquery

$('#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

like image 843
RubbleFord Avatar asked Jun 26 '09 13:06

RubbleFord


People also ask

How to convert JavaScript object to jQuery object?

var $this = $(myObject); $this is a jQuery object. You can create jQuery objects from DOM elements.

How to convert object in jQuery?

Answer: Use the jQuery $. map() Method You can simply use the $. map() method to convert a JavaScript object to an array of items.


1 Answers

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.

like image 160
Peter Avatar answered Sep 21 '22 14:09

Peter