开发者

Jquery selector for "has attribute and parent isn't selected"

Is there a jquery selector that says something like, "has attribute=x and parent hasn't been selected yet"? In the code below, node 1-1开发者_如何学编程 gets added twice to the lower div, but I only want it to be added as part of node 1.

http://jsfiddle.net/XLU4W/


You can try out something like:

var result = $('div[mod_date="1"]');

result.filter(function (i) {
  if(result.has(this.parentNode))
     return false;
  else
    return true;
});


try in this way...

var html = $('div[mod_date="1"]').parent().html()

$('.selection').append(html);

See here


Not directly a selector you described but matching only the first level, you could do:

$('.main > div[mod_date="1"]').clone().appendTo($('.selection'))


If I understand correctly this should do the job: http://jsfiddle.net/ZrjkD/


Went with this: http://jsfiddle.net/JesseAldridge/XLU4W/7/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜