I want to attach one custom CSS class to a footer block using javascript. How can we do that?
<ul class="footer-links col-lg-5 col-md-5 col-sm-12"> 
<li><a href="/about-us">About Us</a></li> 
<li><a href="/contact">Contact Us</a></li> 
<li><a href="#">Careers</a></li> 
<li><a href="/csmarketplace/account/login/">Sell</a></li> 
<li><a href="/terms-and-conditions">Terms & Conditions</a></li> 
</ul>
 Sumit
 
 5,0482 gold badges22 silver badges36 bronze badges
 
 - 
 Do you want to add CSS class to a specific block or whole container?Sumit– Sumit2019年09月16日 06:32:04 +00:00Commented Sep 16, 2019 at 6:32
- 
 @Sumit. Specific block i.e my custom footer blockNafsss– Nafsss2019年09月16日 06:40:37 +00:00Commented Sep 16, 2019 at 6:40
- 
 Please add your block code here you've put in XML file.Sumit– Sumit2019年09月16日 06:48:20 +00:00Commented Sep 16, 2019 at 6:48
- 
 <ul class="footer-links col-lg-5 col-md-5 col-sm-12"> <li><a href="/about-us">About Us</a></li> <li><a href="/contact">Contact Us</a></li> <li><a href="#">Careers</a></li> <li><a href="/csmarketplace/account/login/">Sell</a></li> <li><a href="/terms-and-conditions">Terms & Conditions</a></li> </ul>Nafsss– Nafsss2019年09月16日 07:22:59 +00:00Commented Sep 16, 2019 at 7:22
- 
 Do you want to add CSS class on the ul element?Sumit– Sumit2019年09月16日 07:23:53 +00:00Commented Sep 16, 2019 at 7:23
1 Answer 1
As per your screenshot, you can add your custom class in the footer block by copying /vendor/magento/module-theme/view/frontend/templates/html/footer.phtml file in your theme with below content.
<div class="footer-container">
 <div class="footer">
 <?= $block->getChildHtml() ?>
 <p class="bugs"><?= /* @escapeNotVerified */ __('Help Us Keep Magento Healthy') ?> - <a
 href="http://www.magentocommerce.com/bug-tracking"
 target="_blank"><strong><?= /* @escapeNotVerified */ __('Report All Bugs') ?></strong></a>
 </p>
 <address><?= /* @escapeNotVerified */ $block->getCopyright() ?></address>
 </div>
</div>
EDIT:
In /magento/module-catalog-search/view/frontend/templates/result.phtml file in your theme add below content.
<?php
 $class = "";
 $searchProductCount = $block->getResultCount();
 if ($searchProductCount == 0) {
 $class = "custom_class";
 }
?>
<script>
 require([
 'jquery',
 'jquery/ui'
 ],function($){
 jQuery('.page-footer div.footer').addClass(<?= $class; ?>);
 });
</script>
Hope it helps!!!
 answered Sep 16, 2019 at 7:35
 
 
 
 Sumit 
 
 5,0482 gold badges22 silver badges36 bronze badges
 
 - 
 My condition is if my serach for a particular product results nothing, i want to add class to the block. I am using /magento/module-catalog-search/view/frontend/templates/ result.phtml file. Is there any way to check in footer.phtml that when my search results with no products?Nafsss– Nafsss2019年09月16日 07:38:02 +00:00Commented Sep 16, 2019 at 7:38
- 
 1Thank you. I will try thisNafsss– Nafsss2019年09月16日 07:45:48 +00:00Commented Sep 16, 2019 at 7:45
- 
 Getting this error Magento\CatalogSearch\Block\Result doesn't extends Magento\Framework\App\Helper\AbstractHelperNafsss– Nafsss2019年09月16日 07:49:35 +00:00Commented Sep 16, 2019 at 7:49
- 
 Again error prnt.sc/p6npamNafsss– Nafsss2019年09月16日 07:58:17 +00:00Commented Sep 16, 2019 at 7:58
- 
 1I tried and your solution worked well. Thank you. Accepting this ansNafsss– Nafsss2019年09月16日 11:34:34 +00:00Commented Sep 16, 2019 at 11:34
default