ant
ant

Reputation: 22948

Jquery next selector next() question

+----------------------------------------------------------------------+
| this is div .content                                                 |
|                                                                      |
|              +----------------+                                      |
|              | .left_content  |                                      | 
|              | input inside   |                                      |             
|              +----------------+                                      |
|                                                                      |
|                                                                      |
|                                                      +------------+  |
|                                                      |     span   |  |
|                                                      +------------+  |
|                                                                      |
+----------------------------------------------------------------------+

Hello all, I'm trying to access the span element with jquery but I have some kind of error, here is the deal .content is main div , .left_content div is inside it and span is inside .content but outside .left_content.

Now I can easily access span by using .content span, but since .content, .left_content and span are repeating throughout the website I want to access these elements by clicking on the input inside .left_content div.

So finally I come to my question (from input inside .left_content perspective), how to get div .content , .left_content and span selected?

So far what I've only managed to do is to get .left_content selector by using $(this)parent('div:first')

Upvotes: 0

Views: 473

Answers (2)

Tatu Ulmanen
Tatu Ulmanen

Reputation: 124768

Not sure what you mean, but:

$('input').click(function() {
    var left_content = $(this).parent();
    var content = left_content.parent();
    var span = content.find('span');
});

Upvotes: 0

Magnar
Magnar

Reputation: 28810

This will do the trick:

$(this).closest("div.content").find("span")

Upvotes: 2

Related Questions