开发者

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

开发者 https://www.devze.com 2023-02-08 18:05 出处:网络
I am trying to figure out how to add : <p id=\"sab-contact-tab\"><a href=\"/c开发者_如何学Goontact\" class=\"smcf-link\"></a></p>

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消