admin管理员组文章数量:1194135
I have a function
function toggleSelectCancels(e) {
var checkBox = e.target;
var cancelThis = checkBox.checked;
var tableRow = checkBox.parentNode.parentNode;
}
how can I get a jQuery object that contains tableRow
Normally I would go $("#" + tableRow.id)
, the problem here is the id for tableRow is something like this "x:1280880471.17:adr:2:key:[95]:tag:"
. It is autogenerated by an infragistics control. jQuery doesn't seem to getElementById
when the id is like this. the standard dom document.getElementById("x:1280880471.17:adr:2:key:[95]:tag:")
does however return the correct row element.
Anyways, is there a way to get a jQuery object from a dom element?
Thanks, ~ck in San Diego
I have a function
function toggleSelectCancels(e) {
var checkBox = e.target;
var cancelThis = checkBox.checked;
var tableRow = checkBox.parentNode.parentNode;
}
how can I get a jQuery object that contains tableRow
Normally I would go $("#" + tableRow.id)
, the problem here is the id for tableRow is something like this "x:1280880471.17:adr:2:key:[95]:tag:"
. It is autogenerated by an infragistics control. jQuery doesn't seem to getElementById
when the id is like this. the standard dom document.getElementById("x:1280880471.17:adr:2:key:[95]:tag:")
does however return the correct row element.
Anyways, is there a way to get a jQuery object from a dom element?
Thanks, ~ck in San Diego
Share Improve this question edited Jul 14, 2009 at 6:57 Blixt 50.1k13 gold badges125 silver badges154 bronze badges asked Jul 14, 2009 at 6:52 HcabnettekHcabnettek 12.9k38 gold badges128 silver badges192 bronze badges6 Answers
Reset to default 17Absolutely,
$(tableRow)
http://docs.jquery.com/Core/jQuery#elements
jQuery can take the DOM elements, try with:
$(tableRow)
or
$(checkBox.parentNode.parentNode)
You should be able to pass the element straight in, like this:
$(tableRow)...
I have tested this by creating a reference to a div, then passing it straight into jQuery and it creates the jQuery object for you.
You can call the jQuery function on DOM elements: $(tableRow)
You can also use the closest
method of jQuery in this case:
var tableRowJquery = $(checkBox).closest('tr');
If you want to keep using your ID, kgiannakakis (below), provided an excellent link on how to escape characters with special meaning in a jQuery selector.
See this for how you should escape the id.
try:
var r = $(document.getElementById("XXXX----ID Of Your Row----XXXX"));
now, if document.getElementById doesn't return undefined you can use r as any regular jquery object.
本文标签: javascriptCan I get a jQuery object from an existing elementStack Overflow
版权声明:本文标题:javascript - Can I get a jQuery object from an existing element - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738429993a2086342.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论