jQuery: Click select Previous / Closest div with selector

I’ve being sitting for some while trying to solve a issue which I’m certain is quite simple but it just can’t get it to work. I got this HTML: this is wrapped inside a div (class=row) which is again wrapped inside another div (class=container). Now, when I press either of the three links (Headline, File or Linebreak) I have some JS to do some ajax and then insert some content in the empty div **content**. But for the life of me I just can’t select the div. I should mention, that the block of code is repeated three times, so I have three columns which each contain same dropdown menu with same three links and I want to make it as flexible as possible (before I used some different data-? attributes, but I want to use as few of those if possible). My JS code looks something like this right now: $("#addToColumn li a").click(function() { var elementType = $(this).attr('id'); // I’ve tried this but with no luck: var col = $(this).closest("div#content"); // AND var col = $(this).prev("div#content"); } There are something which confuses me with this DOM tree. I want want each of the dropdown menus to insert something in the right wrapper-div for the right column and I want to try to do it without the use of some numeric “ID’s” but just select the “closest” **content** div and insert the data in this. How do I go about doing that? Any help if very appreciated -Cheers

以上就是jQuery: Click select Previous / Closest div with selector的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准