Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery wrap img with anchor

Tags:

jquery

Hello I have trying to wrap an image with anchor if class has anchor.

jQuery:

if ( $(".views-row:has(a)").length) {
    var noderef = $(this).attr("anchor");
    $(".views-field-field-teaserbox-fid img").wrap("[anchor = "'+noderef+'" ]");
}

HTML:

    <div class="view-content">
        <div class="views-row">

          <div class="views-field-field-node-ref-nid">
           <span class="field-content"><a class="active" href="/all-essentials-inspiring-events">All the essentials of inspiring events.</a></span>
         </div>

         <div class="views-field-field-teaserbox-fid">
            <span class="field-content"><img width="208" height="137" src="http://localhost:8888/sites/default/files/wedding_Giveaway_teaser.jpg?1283880578" alt="" class="imagefield imagefield-field_teaserbox"></span>
    </div>

Also, should I be using a double or single quotes?

like image 545
arkjoseph Avatar asked Sep 08 '10 01:09

arkjoseph


1 Answers

How's this?

$("img.anchor").wrap('<a href="#" />');

ref: http://api.jquery.com/wrap/

like image 118
Scott Avatar answered Nov 05 '22 11:11

Scott