How can I add some html to an exact position within a page?
I am trying to figure out how to add :
<p id="sab-contact-tab"><a href="/c开发者_如何学Goontact" 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
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>";
You have to use simple quotes to delimiter your string (because you have some double quotes in it).
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?
精彩评论