How to add class to a html file loaded via jquery?

前端 未结 1 1005

I\'ve included my header & footer at separate html files using .load() from jQuery. My jQuery code is below:

$(function(){
   $(\"#header\").loa         


        
相关标签:
1条回答
  • 2021-01-21 03:47

    Use complete callback of jQuery.load method.

    .load( url [, data ] [, complete ] )

    When you are invoking addClass method for element, element does not exist in DOM, callback function is invoked when external file is loaded in specified element

    $(function() {
      $("#header").load("page-component/header.html", function() {
        jQuery('#menu-about').addClass('active');
      });
      $("#footer").load("page-component/footer.html", function() {
        jQuery('#menu-about').addClass('active');
      });
    });
    
    0 讨论(0)
提交回复
热议问题