JavaScripter
JavaScripter

Reputation: 4842

Find and remove class

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?

Upvotes: 5

Views: 49579

Answers (3)

Grant
Grant

Reputation: 6329

Off-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"); }

Upvotes: 8

tylerlindell
tylerlindell

Reputation: 1563

$(document).ready(function () {
    $(".instructionRow").click(function(){

        $(this).find('.details').removeClass("hidden");


    });
});

Upvotes: 0

gurudeb
gurudeb

Reputation: 1876

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");
    });
});

Upvotes: 7

Related Questions