• Javascript/jQuery function not working
    4 replies, posted
Can someone tell me what's wrong with this function, because as far as i can tell, it should work. It created the alert, but the bind part does not work. At all. Wtf? [code] function addalert(msg){ var count = $("#ac > div").length; console.log(count); $("#ac").append("<div id=\"alert["+count+"]\" class = \"alert\">Alert: "+msg+"<d id=\"cloze["+count+"]\"><img src=\"red-x-icon.gif\" width=\"25\" height=\"25\" align\"absmiddle\" /></d>"); console.log("<div id=\"alert["+count+"]\" class = \"alert\">Alert: "+msg+"<d id=\"cloze["+count+"]\"><img src=\"red-x-icon.gif\" width=\"25\" height=\"25\" align\"absmiddle\" /></d>"); console.log("#cloze["+count+"]"); $("#cloze["+count+"]").click(function(){ console.log("niggers!"); $("#alert["+count+"]").slideUp(1000); }); } [/code]
uhm [code] console.log("niggers!"); [/code] :golfclap: [editline]07:37PM[/editline] ... and no, I wasn't planning on helping you. Trial and error is what does it for everyone else.
Hehe. But yeah i just trial and error'd it for like half an hour, there really isn't much i can change about those 4 lines of code. I debugged it thoroughly, just to make sure, and everything is working exactly as expected, its just not working! cry.
With a quick test, [code]$("#foo[1]")[/code] doesn't work. Just take the square brackets away and it should work.
[QUOTE=Skorpy;23348877]Just take the square brackets away and it should work.[/QUOTE] Yeah, square brackets inside element id/class names will always cause trouble with your selectors unless they're escaped properly, best to avoid them completely.
Sorry, you need to Log In to post a reply to this thread.