最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - JQuery. Remove a previous sibling in the DOM tree - Stack Overflow

programmeradmin2浏览0评论

I have the next code dynamically created using JQuery. Theere are multiple row class divs placed one under the other.

<div class="row">
    ....
</div>
<div class="row">
   <div class="line_type"></div>
   <div class="download_value"></div>
   <div class="flag"></div>
   <div class="email"></div>
   <div class="prize"></div>
</div>
<div class="row">
    ....
</div>

After i create these divs I have a "pointer" to a specific div which is of class row. In JQuery, how do i make it so I go down the DOM tree, until i reach the div of class line_type and download_value and remove them both, and also I'd like to go one more node down, at the div of type email and change some of it's CSS attributes.

I was not able to find anything on the web, maybe it's cause i'm a noob at these still.

I have the next code dynamically created using JQuery. Theere are multiple row class divs placed one under the other.

<div class="row">
    ....
</div>
<div class="row">
   <div class="line_type"></div>
   <div class="download_value"></div>
   <div class="flag"></div>
   <div class="email"></div>
   <div class="prize"></div>
</div>
<div class="row">
    ....
</div>

After i create these divs I have a "pointer" to a specific div which is of class row. In JQuery, how do i make it so I go down the DOM tree, until i reach the div of class line_type and download_value and remove them both, and also I'd like to go one more node down, at the div of type email and change some of it's CSS attributes.

I was not able to find anything on the web, maybe it's cause i'm a noob at these still.

Share Improve this question asked Aug 28, 2012 at 14:52 AndreiBogdanAndreiBogdan 11.2k14 gold badges65 silver badges110 bronze badges 2
  • Create a jsfiddle, to show your DOM structure and what you have tried so far. – Alexander Wigmore Commented Aug 28, 2012 at 14:54
  • 2 You mean you just want to remove all .line_type and .download_value elements, and edit the style of all .email elements? – Mitya Commented Aug 28, 2012 at 14:55
Add a ment  | 

3 Answers 3

Reset to default 4

I have a "pointer" to a specific div which is of class row ->

Assuming that you have the this object of the corresponding div with class row.. then you can use .find to get the line_type and download_value inside that div.

$(this).find('.line_type').remove();
$(this).find('.download_value').remove();

Then you can use the same .find to get the div with class email and access the .css

$(this).find('.email').css(/* You code*/);

Assuming row_pointer points to the row in question:

$('.line_type, .download_value', row_pointer).remove();
$('.email', row_pointer).css(...);

check this out

$('div.row').bind('click', function() {
    $this = $(this);
    $('div.line_type, div.download_value', $this).remove();
      $('div.email', $this).css('background-color', 'red');
});

http://jsfiddle/YvyE3/

发布评论

评论列表(0)

  1. 暂无评论