I have the following structure:
<li id="0" class="instruction">
<div class="row1">
title
</div>
<div class="row2 details hidden">
details
</div>
</li>
css for hidden is: display: none
I'd like when user clicked the instruction, then show the details div.
$(document).ready(function () {
$(".instruction").click(function(e){
$(e).find('.details').removeClass("hidden");
});
});
Tried to implement something like above, but doesn't work. any idea?
I have the following structure:
<li id="0" class="instruction">
<div class="row1">
title
</div>
<div class="row2 details hidden">
details
</div>
</li>
css for hidden is: display: none
I'd like when user clicked the instruction, then show the details div.
$(document).ready(function () {
$(".instruction").click(function(e){
$(e).find('.details').removeClass("hidden");
});
});
Tried to implement something like above, but doesn't work. any idea?
Share Improve this question edited May 4, 2014 at 14:24 martynas 12.3k3 gold badges58 silver badges61 bronze badges asked May 4, 2014 at 14:10 JavaScripterJavaScripter 4,84210 gold badges39 silver badges45 bronze badges 1 |3 Answers
Reset to default 8Off-answer, but ref for Googlers - vanilla Javascript option for finding a class and removing a class
// Finding all elements of a class (creates an array of results)
let x = document.getElementsByClassName("today");
// If it exists, remove it.
if(x.length > 0) { x[0].classList.remove("today"); }
You have written '.instructionRow' but as per the html it should be '.instruction'. And use $(this) to refer to the element that is clicked. And usage of 'on' (https://api.jquery.com/on/) is better...
$(document).ready(function () {
$(".instruction").on('click', function(e){
$(this).find('.details').removeClass("hidden");
});
});
$(document).ready(function () {
$(".instructionRow").click(function(){
$(this).find('.details').removeClass("hidden");
});
});
e
, usethis
, like this$(this).find('.details').removeClass("hidden");
– Amit Soni Commented May 4, 2014 at 14:11