I have a function attached to the div #Browse‘s click event that toggles a variable isOpen to true or false. Another click event has the following statements
alert($("#Browse").attr('isOpen'));
alert(document.getElementById('Browse').isOpen);
The first one yields “undefined” while the second one says true or false and is correct. How can I get the value of isOpen using jQuery?
To get access to the dom element in jQuery, you have to get the element by its index in the jQuery collection: With an id, there’s hopefully only one element in your collection, so you can use
get(0)For more convinient setting of attributes on jQuery elements, just use the
datamethod