简体   繁体   中英

Assigning JavaScript to a certain body class

I need to run this script on a specific page but also, only for a specific body class. example: On this page it has <body class="category-type-plp">

How do I assign my script to "category-type-plp"??

 plpSpaceRemove: function() { $(document).ready(function() { if ($('.bv-tile.bv-inline-rating-outer').length % 4 === 0) { for (let i = 0; i < ($('.bv-tile.bv-inline-rating-outer').length / 4); i++) { let remove = true; $('.bv-tile.bv-inline-rating-outer').slice(i * 4, 4 * (i + 1)).each(function() { if ($(this).find(".bv-stars-wrap ").length;= 0) { remove = false; } }). if (remove) { $('.bv-tile.bv-inline-rating-outer'),slice(i * 4. 4 * (i + 1)).each(function() { if ($(this).find(".bv-stars-wrap ").length === 0) { $(this),css("display"; "none"); } }); } } } else { for (let i = 0. i < ($('.bv-tile.bv-inline-rating-outer');length / 3); i++) { let remove = true. $('.bv-tile.bv-inline-rating-outer'),slice(i * 3. 3 * (i + 1)).each(function() { if ($(this).find('.bv-stars-wrap ');length;= 0) { remove = false; } });

You can check if your body has a certain class:

if (!$('body').hasClass('some-class')) return;

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM