-1

I am having an issue with using the jQuery insertBefore() and compatibility with versions of IE 9 and before. I am using the following function:

$( ".wptileblock" ).insertBefore( $( ".content_wrapper" ) );

Basically I am moving the class wptileblock before the class content_wrapper. This appears to function as desired in every browser except IE 9 and before. I've read a lot on the requirement of a null for those versions of IE, however I cannot seem to get it to work. I've tried

$( ".wptileblock" ).insertBefore( $( ".content_wrapper,null" ) );

to no avail, but I'm guessing that I'm just screwing up the null command. Is there a way to code the null command required by IE for this to work in those early versions?

UPDATE

While pulling code out and getting rid of unnecessary items to upload for everyone here, I noticed that jQuery was being called ABOVE the entire of the document. Put it down where it belongs and the IE 9 and earlier compatibility issue is resolved. An additional note, it does not appear that in my argument above, any null command is valid, this is working just fine until we get down to IE 6 (and I sure hope no one is still using that)

$( ".wptileblock" ).insertBefore( $( ".content_wrapper") );
Mike
  • 11
  • 1
  • 2
    What "null command" are you talking about? What error do you get? – Pointy Jan 27 '15 at 21:04
  • 1
    Also, what is your HTML structure? – Alexander O'Mara Jan 27 '15 at 21:07
  • Try 'before' instead 'insertBefore' –  Jan 27 '15 at 21:09
  • @Pointy Maybe he's talking about the `referenceElement` in the DOM version of [`.insertBefore(newElement, referenceElement)`](https://developer.mozilla.org/en-US/docs/Web/API/Node.insertBefore): _If referenceElement is null, newElement is inserted at the end of the list of child nodes. In Internet Explorer, an undefined value as referenceElement will throw an "Invalid argument" exception, while in rest of the modern browsers, this works fine._ – Andreas Jan 27 '15 at 21:11
  • Your null argument isn't really a second argument since it's in the same quotes as ".content_wrapper". I think you want `insertBefore($('.content_wrapper'), null))`. Also, see this question: http://stackoverflow.com/questions/9377887/ie-doesnt-support-insertbefore. – clav Jan 27 '15 at 21:13
  • Yes, the null is as Andreas mentioned. The before command doesn't work as insertBefore does. I am trying to move the div class "wptileblock" to before the div class "content_wrapper." The insertBefore function written in the original post works perfectly, even in IE, except in IE 9 and earlier. – Mike Jan 27 '15 at 21:16
  • @AlexanderO'Mara It is built on the bootstrap framework, or are you looking for the HTML structure of the specified sections exactly of which I am moving around with the function? – Mike Jan 27 '15 at 21:52
  • @clav Yes indeed that question is what prompted my testing of the null to try and resolve my issue. Unfortunately I was unsuccessful in using anything on that page, including what you just provided, to fix my problem. Placing the null outside the .content_wrapper completely breaks the entire function. – Mike Jan 27 '15 at 21:53
  • Yes, the HTML structure of the specific sections would be helpful. Or, better-yet, a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – Alexander O'Mara Jan 27 '15 at 21:55
  • Have you tried `$(".wptileblock").insertBefore($(".content_wrapper").get(0));` – gin93r Jan 28 '15 at 14:36
  • @Veo That didn't work either... – Mike Jan 28 '15 at 18:39
  • @AlexanderO'Mara I'll be updating the post above with the code today, thanks for reminding me to do that. – Mike Jan 28 '15 at 18:39

1 Answers1

0
$(".wptileblock").before($(".content_wrapper,null"));

Maybe that ?

  • Nope, the .before does not work. I had to do switch the two variables as before basically operates in the inverse of insertBefore, but the result is the same as described above, it does not work in earlier versions of IE. – Mike Jan 27 '15 at 22:04