I have the following HTML markup:
<div id="step1" class="step">
<h1>Enter code</h1>
<p><input type="text" value="<%= @groupCode %>" name="group_code" class="span3" />
<a class="btn btn-primary btn-medium">
Next »
</a>
</p>
</div>
<div id="step2" class="step" style="display: none">
<p>Hello World</p>
</div>
Upon clicking the link (.btn
) I am needing to show the next parent div (#step2
). I am designing this as a registration process, so there will be multiple parent divs (all named with step{:id})
Any help is much appreciated!
The parent() is an inbuilt method in jQuery which is used to find the parent element related to the selected element. This parent() method in jQuery traverse a single level up the selected element and return that element. Here selector is the selected elements whose parent need to find.
jQuery parentsUntil() Method The parentsUntil() method returns all ancestor elements between the selector and stop. An ancestor is a parent, grandparent, great-grandparent, and so on.
The :parent Selector page on jQuery says: Select all elements that have at least one child node (either an element or text). So $('div') would select all divs and $('div:parent') would select only those with children.
You should be able to use something like:
//This should access the parent (step1), then the next element (step2)
$(this).parent().next()
jQuery('.btn').click(function(){
jQuery(this).closest('.step').next().show();
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With