I'm trying to add a class to an existing div that has multiple classes but doesn't work, the class is not added. I've added this on header (it's s shopify template):
<script type="text/javascript">
jQuery(document).ready(function($) {
$('div.wk_right_header_inner wk_font_weight_bold wk_font_family wk_paddingbottom10').addClass('new-class');
});
</script>
The div looks like this (with no space after <):
<div class="wk_right_header_inner wk_font_weight_bold wk_font_family
wk_paddingbottom10"> Test </div>
Thanks
You need to do
$('div.wk_right_header_inner.wk_font_weight_bold.wk_font_family.wk_paddingbottom10').addClass('new-class');
});
Because now it thinks the other classes are sub elements.
Have a look a this:
jQuery(document).ready(function($) { $(' .wk_right_header_inner ').addClass('new-class'); });
.new-class { color:red; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <div class="wk_right_header_inner wk_font_weight_bold wk_font_family wk_paddingbottom10"> Test </div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.