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
Add a ment  | 

3 Answers 3

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