I need to retrieve the element with specific class which is placed below in DOM. For example:
<div>
<a onclick="someMethod(this)">
</div>
<div class="specificClass">
</div>
In someMethod I have the anchor but need to retrieve the first element with class “specificClass” which is placed below.
Update. The position of <div class="specificClass"> is not specified. The only thing I know – it is placed below
DEMO: http://jsfiddle.net/reKwQ/1/
Instead of using the
onclickattribute, give your anchor a class or ID:Then bind a click event to it using jQuery and go from there:
This works because you have a list of matched elements containing both the anchor and target elements, that will be in the order of discovery.
Once we find the thing we clicked on, we can accept the next available
.specificClasselement as our result.DEMO: http://jsfiddle.net/reKwQ/1/