Reputation: 2393
I am a Javascript noob and I need help adding a codeblock after a div.
i want to add code after the following class
<div class='post-body entry-content'>
So mu JQuery code must be
$('post-body entry-content').add('<img border="0" src="http://4.bp.blogspot.com/-C4vvMEB9MyI/TfW0lduV2NI/AAAAAAAAAZc/N7HL1pUusGw/s1600/some image.png" />');
Right ??
If I am wrong please correct me !
Upvotes: 0
Views: 2848
Reputation: 187030
You can insert the code block inside the document ready event.
$(function(){
$('div.post-body.entry-content').after('<img border="0" src="http://4.bp.blogspot.com/-C4vvMEB9MyI/TfW0lduV2NI/AAAAAAAAAZc/N7HL1pUusGw/s1600/some image.png" />');
});
Upvotes: 1
Reputation: 272106
Depending on what you want:
// inside, before all existing content
$(".post-body.entry-content").prepend('<img src="some image.png" />');
// inside, after all existing content
$(".post-body.entry-content").append('<img src="some image.png" />');
// outside, after
$(".post-body.entry-content").after('<img src="some image.png" />');
Upvotes: 1
Reputation: 490213
No, that is incorrect.
.
to select by class and join them together if you want to match elements which include all classes.after()
.$(function() {
$('.post-body.entry-content')
.after('<img border="0" src="http://4.bp.blogspot.com/-C4vvMEB9MyI/TfW0lduV2NI/AAAAAAAAAZc/N7HL1pUusGw/s1600/some image.png" />');
});
Upvotes: 1