I'm trying to inject HTML into a div on a page that I don't have access to the HTML, but can't seem to get the function right.
The HTML structure looks a bit like this:
<body class="ly_productdetails ProductDetails en en_GB">
<div id="page">
<div class="container">
<div id="main" class="container">
<div id="info">
<h2 itemprop="name">Product Name</h2>
<p><span itemprop="price">£55.00</span></p>
</div>
</div>
</div>
</div>
</body>
and the JS looks like this:
$(document).ready(function() {
var $body = $(document.body);
if (body.attr('class').match(/body.ly_productdetails.ProductDetails.en.en_GB/).length > 0) {
$('#main .container').prepend("<div id="recommendations"><ul<li>Cross sell 1</li><li>Cross sell 2</li><li>Cross sell 3</li></ul></div>");
}
});
I am green when it comes to JS so I'm, not confident in the above but can't see what I'm doing wrong.
Could some one take a look and let me know what I'm doing wrong?
Thanks in advance,
Adam
JS Fiddle https://jsfiddle.net/zL8L7zdk/
bodyelement on the page?