aynakolik
aynakolik

Reputation: 99

Jquery Html Element Selector

I have a HTML code like this,

<div class="panel-footer">
    <div class="post-activity">
        <i class="loading-icon"></i>
        <button onclick="ChangeColor(this);">Change Color</button>
    </div>
    <div class="comments-ch"></div>
</div>

When I write this Jquery code

function ChangeColor(element)
{
    $(element).closest(".panel-footer").find(".comments-ch").css("background-color","#CC0000")
}

Not working for class = comments-ch, But If I write this code like this,

    function ChangeColor(element)
    {
        $(element).closest(".panel-footer").find(".post-activity").css("background-color","#CC0000")
    }

working.

Summary, first div under the "panel-footer" is OK, but the second/last div NOT OK.

How can i reach the second/last div element? Thanks

Upvotes: 0

Views: 57

Answers (2)

Syed Ali Taqi
Syed Ali Taqi

Reputation: 4974

Try .show() after setting the CSS:

function ChangeColor(element) {
    $(element).closest(".panel-footer").find(".comments-ch").css("background-color", "#CC0000").show()
}

Upvotes: 1

Control Freak
Control Freak

Reputation: 13243

When using a class selector, make sure you specify a period in front.

For example, in:

$(element).closest(".panel-footer").find("comments-ch").css("background-color","#CC0000")

Change from find("comments-ch") to find(".comments-ch")

Upvotes: 1

Related Questions