开发者

insert content to the first selector

I created a checkbox which I want to insert before a cloned phrase and list.


$("p:contains('text'), ul:last",e).clone().prepend(myCheckbox);

My checkbox is now inserted before each phrase and each list. I just want to insert the checkbox before the phrase. Is that possible?

Thank you.

Edit: HTMl-Structure to clone:

<p>Text</p>
<ul>
  <li>Listpoint</li>
  <li>Listpoint</li>
  <li>Listpoint</li>
</ul>

This is what it shoudl look like: <input type='checkbox'> <p>Text</p> <ul> <li>Listpoint</li> <li>Listpoint</li> <li>Listpoint</li> </ul>

But it looks like: <input type='checkbox'> <p>Text</p> <input type='che开发者_JAVA百科ckbox'> <ul> <li>Listpoint</li> <li>Listpoint</li> <li>Listpoint</li> </ul>


You could use .filter() to trim the results:

$("p:contains('text'), ul:last", e).clone().filter('p').prepend(myCheckbox);


Use before():

$('p:contains("text"), ul:last', e).clone().before(myCheckbox);

Live demo: http://jsfiddle.net/simevidas/Ye5bS/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜