In this loop, I’m trying to add an event handler to each “count”. The event handler calls a function “hideAll()”, whose input value is “count”.
I am doing so by adding HTML code under the ID “next”, using JQuery’s insertBefore() method.
for (count=1; count<=3; count++)
{
$('<a href="#" onclick="hideAll(' + count + ');return false;">' + count + '</a>').insertBefore("#next");
}
So when I run it, it gets added, but for some weird reason, it get’s added like this:
<a onclick="hideAll(1);return false;" href="#">1</a>
The string href=”#” is getting moved over to the end. I can’t figure out why.
I tried checking the quotation marks and everything. Everything seems perfect, no idea why it’s doing that.
What browser are you viewing it in?
Some browsers, when viewing the dom, shows you its “final” source after it has interpreted the markup.
Make sure you “View Page Source”, and not “Inspect Elements” to get the pure pre-interpreted markup.
Ultimately, though, the order of attributes are irrelevant, so it should be fine for your purposes?