English 中文(简体)
页: 1 ery until until until
原标题:jQuery remove all elements until id= whatever found

Need to remove all the code from the start tag to the next

我曾试图这样做。

$( #page1 ).remove();

但是,这只能消除双方之间的分歧。

我不知道第1页和2页标之间的其他内容,因为根据页上表格的类型,该代码是动态添加的。

<div id= page1  name= page1 >
 ...
</div> 
<div id= another element  />
<div id=yet  another element  />
...
<!-- Need to remove from page1 to here -->
<div id= page2  name= page2 >
 ...
</div>
最佳回答

假设你想要删除<代码>1和直至>>>><2>。 你可以这样做:

$("#page1").nextUntil("#page2").andSelf().remove();

<http://jsfiddle.net/markcoleman/PCLvK/1/"rel=“noretinger”> jsfiddle

问题回答

If they are nested (?) and you want to delete the children in the page1 div, you could do something like this maybe:

$( #page1  > div).remove();

或者,如果你想有选择性地这样做——而且只在第1页中删除某些零件——你可以增加一个类别,并做同样的事。

如何做这样的事情:

var last = null;
var curr = $( #page1 );
while (curr.attr( id ) !=  page2 ) {
    if (last != null) {
        last.remove();
    }
    last = curr;
    curr = curr.next();
}
if (last != null) {
    last.remove();
}
$( [id^="#another"]:not([id^="#page"]) ).each(function()
{
   $(this).remove();
});

删除从<代码>another开始的所有内容,但排除了从<代码><>>>>开始的内容。

当你需要将“ID”转至“JQuery”时,很容易使用“阶级”。 可能构成的每个标签,必须删除,加上“removeSet1”。 然后,当需要时,请您援引$(revoveSet1”)remove()。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签