How can I add some html to an exact position within a page?

213 views Asked by At

I am trying to figure out how to add :

<p id="sab-contact-tab"><a href="/contact" class="smcf-link"></a></p>

right after :

<div id="footer">

Here is my code:

jQuery(document).ready(function() {
    var prependHTML = "<p id="sab-contact-tab"><a href="/contact" class="smcf-link"></a></p>";
    jQuery(prependHTML).prepend("#footer");
});

Is this code correct? if not what is the right code?

Thanks,

Michael Sablatura

3

There are 3 answers

2
sissonb On BEST ANSWER
var prependHTML = "<p id="sab-contact-tab"><a href="/contact" class="smcf-link"></a></p>";

Should be

var prependHTML = '<p id="sab-contact-tab"><a href="/contact" class="smcf-link"></a></p>';

or

var prependHTML = "<p id=\"sab-contact-tab\"><a href=\"/contact\" class=\"smcf-link\"></a></p>";
2
tobyodavies On

In that situation i would always use jQuery('#footer').append(appendHTML); rather than appendTo but i don't think that would be functionally any different, is the code you posted not working?

0
CronosS On

You have to use simple quotes to delimiter your string (because you have some double quotes in it).