jQuery: Selecting the text when p contains a listpoint
I've got some comments in a guestbook. p containins '(In [ 'sometimes. The '(In [' sometimes contains a list.
<div class="comment searchable">
<p>
(In <a class="changeset" href="/../" sets mynumber">[Phonebook]</a>)
</p>
<ul><li><tt>Name</tt>, <tt>Number</tt>
</li></ul>
<p>is <a class="is new entry" href="/../mynumber">new entry</a>
</p>
</div>
This is how I get all '(In' 's and some text in the same line. I insert them in a 'box' after a div.
$("<div id='createDiv' style='border:1px outset #999966;padding:1em;margin-top:1em'></div>").insertAfter("#changelog");
$(&开发者_如何学运维quot;#createDiv").append($("p:contains('In [')").clone());
But how do I select and insert the whole text when the comments also contains a listpoint?
I'm using jQapi as a reference which is very useful. I was looking for sth like: p:contains('li').
Thank you in advance for any hint.
Edit: What should come out:
(In [Phonebook]) Name, Number is new entry.
Now it is: (In [Phonebook])
I think what you want is replacing:
$("p:contains('In [')").clone()
With:
$("p:contains('In [')").closest("div").clone()
//or...
$("div.comment:contains('In [')").clone()
Or if you just want the children:
$("p:contains('In [')").closest("div").children().clone()
//or...
$("div.comment:contains('In [')").children().clone()
You have a few options here, depending on what you want your edit to look like. If you just cared about the text for example, this would suffice:
$("div.comment:contains('In [')").text()
I guess you are lookin for :has()
is this:
(In [Phonebook]) Name, Number is new entry
what you wanted?
$("div p:contains('In [')").parent().text()
精彩评论