admin管理员组文章数量:1415673
if i use this $("div:jqmData(role='page')")
it will return me the array of pages in my DOM
object. But jquerymobile creates a default blank page which doesnt have any ID so i cant actually get it by its ID. instead i use $("div:jqmData(role='page')").get(0)
to get the first DOM object representing the default Page jquery created.
but if i use $("div:jqmData(role='page')").get(0).remove()
it doesnt remove the page, but it returns errors.
can anyone teach me on how to remove that DOM? thanks!
if i use this $("div:jqmData(role='page')")
it will return me the array of pages in my DOM
object. But jquerymobile creates a default blank page which doesnt have any ID so i cant actually get it by its ID. instead i use $("div:jqmData(role='page')").get(0)
to get the first DOM object representing the default Page jquery created.
but if i use $("div:jqmData(role='page')").get(0).remove()
it doesnt remove the page, but it returns errors.
can anyone teach me on how to remove that DOM? thanks!
Share Improve this question edited Aug 15, 2012 at 11:45 Vinay 6,8774 gold badges34 silver badges51 bronze badges asked Aug 15, 2012 at 11:41 Chinchan ZuChinchan Zu 9185 gold badges20 silver badges40 bronze badges 1- "it will return me the array of pages" - Correction: it will return a jQuery object with your pages. – nnnnnn Commented Aug 15, 2012 at 11:49
3 Answers
Reset to default 5.remove()
is a jQuery method, so you need a jQuery object to call it on. .get
returns a DOM element though. Use .eq
[docs] instead to get the element as jQuery object:
$("div:jqmData(role='page')").eq(0).remove()
The .get()
function returns the DOM element itself, so you won't be able to chain jQuery functions (such as .remove()
) after it. If you need to do that, use the .eq()
method which returns that single DOM element wrapped in a jQuery object, allowing you to chain.
It doesn't work because .get()
returns the underlying DOM element, not the jQuery object. You can use .eq()
to access the jQuery object at a specific index.
So this should work:
$("div:jqmData(role='page')").eq(0).remove()
本文标签: javascriptremoving a DOM object from an array of DOMStack Overflow
版权声明:本文标题:javascript - removing a DOM object from an array of DOM - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745220985a2648393.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论