jquery prepend to body not working for me
I'm trying to use jquery to prepend a couple of hidden input tags to the start of the body of my JSP.
$("body").prepend('<input id="SCROLL_OFFSET_X" name="SCROLL_开发者_开发技巧OFFSET_X" type="hidden" value="<%=myJSPPageVariableX%>"/>');
$("body").prepend('<input id="SCROLL_OFFSET_Y" name="SCROLL_OFFSET_Y" type="hidden" value="<%=myJSPPageVariableY%>"/>');
For some reason these are not appearing when I use firebug to view the HTML. Am I doing something wrong here?
Kind Regards,
Jason.
I just stumbled across this question whilst having the same problem. I know this is a really old post, but I'm going to answer anyway.
Basically, you have to give the body tag a class, or better still, an ID, and use that as your selector. It's a shame you can't just use body
, but we'll have to live without
Wouldn't that result in visible html elements outside the body of the document?
Maybe that isn't allowed.
[Edit] The comments are correct, prepend appends inside the selected element.
精彩评论