Reputation: 22720
I have following HTML
<div id="header1" class="toggle">Section 1 : Create an account</div>
<div id="section1">
First name: <input type="text" name="firstname" /><br />
Last name: <input type="text" name="lastname" />
</div>
I want to disable all input
elements which are in a div
which is next to div
with class="toggle"
.
In above exmple div
with id="header1"
have class="toggle"
,I want to disable all input
elements which are in div
next to it i.e. input elements within div
with id="section1"
.
I tried $('.toggle').next(div input)).attr("disabled", true);
but no luck. I am not sure if we can use nested selector in next()
.
Upvotes: 0
Views: 236
Reputation: 35793
Use next and then find:
$('.toggle').next('div').find('input').attr("disabled", true);
Or using an expanded version of 3nigmas answer:
$('div.toggle+div input').attr("disabled", true);
Upvotes: 2
Reputation: 31043
See Next Adjacent Selector (“prev + next”)
$("div.toggle+div").find(":input").prop("disabled",true);
Upvotes: 2