user1765862
user1765862

Reputation: 14205

on dom ready append html element using jquery

I have legacy database with holds beside rest html source which is used by a client to render some page snippets. I want to fetch all images inside #mainNewsBody .news p and to add link to that image rel='superbox[image]'

Now it's

<img src="http://www.mysite.com/images/DSCF1087.JPG" /> and it should be

<img src="http://www.mysite.com/images/DSCF1087.JPG" rel='superbox[image]'/>

how can I achive this using jquery on dom ready?

Thanks everyone.

Upvotes: 0

Views: 298

Answers (3)

CD..
CD..

Reputation: 74166

$(function(){
 $('#mainNewsBody .news img').attr('rel', 'superbox[image]');
});

Upvotes: 1

phnkha
phnkha

Reputation: 7892

$(document).ready(function(){
    $('#mainNewsBody .news p img').attr('rel', 'superbox[image]');
});

Upvotes: 0

Billy Moat
Billy Moat

Reputation: 21050

$(document).ready(function() {

    $('#mainNewsBody .news p img').attr("rel", "superbox[image]");

});

Upvotes: 0

Related Questions