DevilDevel
DevilDevel

Reputation: 1

Add class to end of div

I have a div tag labeled

<div id = "product-tabs" class="gen-tabs gen-tabs--style1"> 

I need to add accor to the end of the class section

gen-tabs gen-tabs--style1 accor

Using jQuery

$(window).load(function(){
    $(".product-2-square-furniture-leg").parent(".gen-tabs--style1").addClass(".accor");    
}) 

This will be on a specific page body is product-2-square-furniture-leg. Perhaps I have the wrong path?

Upvotes: 0

Views: 515

Answers (1)

ntgCleaner
ntgCleaner

Reputation: 5985

Remove the . (dot) from your class

$(window).load(function(){
    $(".product-2-square-furniture-leg").parent(".gen-tabs--style1").addClass("accor");    
}) 

The addClass() already specifies it as a class, you don't need to use the dot when it comes to those things like hasClass, addClass, removeClass

Also, this could just be me, but I like to use closest() instead of parent() (and find() instead of children()). Not sure if that's detrimental to speed or anything, but hey - you're using jQuery, so speed doesn't matter, right?

Upvotes: 2

Related Questions