javascript - removing a DOM object from an array of DOM - Stack Overflow

if i use this $("div:jqmData(role='page')") it will return me the array of pages in

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()

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745220985a4617247.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信