Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to append something right before the closing </head> tag using jQuery?

Tags:

jquery

I tried this but it doesn't seem to be working:

$('</head>').appendTo("<meta http-equiv='refresh' content='0;url=http://google.com'>");
like image 508
Brandon Avatar asked Dec 22 '22 16:12

Brandon


1 Answers

First, the item you're trying to append isn't valid HTML, it's simply the closing head tag and presumably already exists in the document. Second, you shouldn't be using appendTo in this case, but rather append:

$('head').append("<meta http-equiv='refresh' content='0;url=http://google.com'>");

Third, there's no reason to do either because you could just as easily change the location using javascript as well.

window.location = "http://google.com";
like image 76
tvanfosson Avatar answered May 13 '23 12:05

tvanfosson