1

I just created one footer content in .js page now I need to append that content for a class in a page,But some syntax error in dynamically created footer.I dont know how to create it dynamically.
Please any sugesstion?

$(document).ready(function(){
    var footer="<footer class='subFooter col-lg-12 col-md-12'>"
        "<div class='col-lg-12 col-md-12' style='padding-top:35px;'>"
            "<p style='display:inline;color:#fff'>@ xxxxx Limited</p>"
            "<img src='images/aaa.png'  class='pull-right'>"    
            "<img src='images/bbb.png'  class='pull-right'>"    
        "</div>"
    </footer>";
    $('#footer').append(footer);
});

This footer only I need to load in #footer

1
  • 1
    you're not concatenating the strings "<footer> ...." + "<div> ...." Commented May 30, 2017 at 12:47

4 Answers 4

3

You have to concatenate these strings (added the + characters at the end of the lines and the missing quotes before the </footer> closing):

$(document).ready(function() {
  var footer = "<footer class='subFooter col-lg-12 col-md-12'>" +
     "<div class='col-lg-12 col-md-12' style='padding-top:35px;'>" +
       "<p style='display:inline;color:#fff'>@ 2023 by Camion Ligistics Limited</p>" +
       "<img src='images/Artboard 21 copy.png' id='twitterIcon' class='pull-right'>" +
       "<img src='images/Artboard 21.png' id='fbIcon' class='pull-right'>" +
     "</div>" +
    "</footer>";
  $('#footer').append(footer);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="footer"></div>

If you have multiple footers you want to use a class instead of an id:

 <div class="footer"></div>

And then in the JavaScript side:

 $(".footer").append(...);
Sign up to request clarification or add additional context in comments.

6 Comments

@AlivetoDie Thanks! :)
Heh thanks.But, am using #footer 5places in my code,its appending only once.
its a nav-tabs..for each tab i need to load that footer.what to do?
@krish your tabs will open new pages?
no complete code is in a single page only.. i have used multiple div.Using id am loading the div.For each tab separate div.
|
1
var footer="<footer class='subFooter col-lg-12 col-md-12'>" + 
        "<div class='col-lg-12 col-md-12' style='padding-top:35px;'>" +
            "<p style='display:inline;color:#fff'>@ 2023 by Camion Ligistics Limited</p>" +
            "<img src='images/Artboard 21 copy.png' id='twitterIcon' class='pull-right'>"   +
            "<img src='images/Artboard 21.png' id='fbIcon' class='pull-right'>" +
        "</div>"+
    "</footer>";

Comments

1

Here is the working code. Your code had double quotes which are not needed. Instead have the entire HTML in one-line. If you take them in next line with double quotes than you need to append those with + sign.

$(document).ready(function() {
  var footerHTML = "<footer class='subFooter col-lg-12 col-md-12'><div class='col-lg-12 col-md-12' style='padding-top:35px;'><p style='display:inline;color:#fff'>@ 2023 by Camion Ligistics Limited</p><img src='images/Artboard 21 copy.png' id='twitterIcon' class='pull-right'><img src='images/Artboard 21.png' id='fbIcon' class='pull-right'></div></footer>";
  $('#footer').html(footerHTML);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="footer"></div>

Comments

1

Alternatively, if you can use ES6, you can use the multi-line string approach, for better clarity:

$(document).ready(() => {
  var footer = `
    <footer class="subFooter col-lg-12 col-md-12">
      <div class="col-lg-12 col-md-12" style="padding-top:35px;">
        <p style="display:inline;color:#fff">@ 2023 by Camion Ligistics Limited</p>
        <img src="images/Artboard 21 copy.png" id="twitterIcon" class="pull-right">
        <img src="images/Artboard 21.png" id="fbIcon" class="pull-right">
      </div>
    </footer>`;

  $('#footer').append(footer);
});

This also allows you to use double quotes for more familiar html.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.