I am having some troubles understanding why this doesn't work as I expect. Basically I have a select like this:
<select id="myId" data-option-name="myOption" onchange="_ui.updateOptions($(this));">
....
</select>
and
updateOptions: function(element) {
var x = element.data("optionName");
}
In another branch of the code I want to do this
var x = $("#myId").data("optionName");
but I get undefined as a result, while it works inside updateOptions.
In addition, if I do this (where element = $(this) of the "myId" select)
updateOptions: function(element) {
var y = (element == $("#myId"));
}
I get that y is false.
Am I missing something? How can I access data-option-name from inside $("myId")?
EDIT: it just occurred to me that probably (element == $("#myId"))
returns false because they are 2 different jQuery objects, although they are referencing the same DOM element.
EDIT2: forgot the hashes in the posted code.. they are present in my source.
EDIT3: some more details.. these were taken using firebug with a breakpoint inside updateOptions
$("#myId").attr("id") = "myId";
element.attr("id") = "myId";
$("#myId").data("optionName") = undefined;
element.data("optionName") = "myValue";
$("#myId").data("option-name") = undefined;
element.data("option-name") = "myValue";
$("#myId").attr("data-option-name") = undefined;
element.attr("data-option-name") = "myValue";
EDIT4:
$("#myId").is(element) returns false