Here’s my jQuery code (this is a bookmarklet, so it’s all done by using my jQuery script to generate this):
$("#audience").prepend("<div id=\"plugbot-gui\"></div>");
$("#plugbot-gui").css("width", "348px").css("height", "48px").css("background-color", "#0A0A0A").css("opacity", "0.9100000262260437");
$("#plugbot-gui").prepend("<br /><a href=\"#\" id=\"autowoot-btn\">AUTOWOOT</a>");
$("#plugbot-gui").append("<a href=\"#\" id=\"automeh-btn\">AUTOMEH</a>");
$("#plugbot-gui").append("<a href=\"#\" id=\"autoqueue-btn\">AUTOQUEUE</a>");
$("#plugbot-gui a").css("font", "bold 12px arial").css("color", "#fff").css("text-align", "center").css("margin-left", "32px");
$("#plugbot-gui a:first-child").css("margin-left", "0px !important");
Everything appears (the text), and is all exactly where I want it… but when I try to use a click() handler in jQuery by using one of the IDs, e.g. autowoot-btn, it doesn’t pick it up. It may also be important to note that, even though they’re link tags, the cursor doesn’t change when hovering over it.
Thanks!
As your
#autowoot-btnappend to DOM after page load so you need delegate event handler (aka live).You need to apply this procedure for all of your element that coming to DOM after page load.
There is another process called
.delegate()It will look like:
.on()method declaration process for delegate is:What about
.live()It has been deprecated in since jQuery > 1.7
Note
Avoid escape characters