javascript - How to make a Jquery snippet only apply to some certain tags? -


i came across snippet function wrap img tag span , make image background image of span. question is, how can make apply img tag or img tags in div?

$(document).ready(function(){

$("img").load(function() {     $(this).wrap(function(){         return '<span class="image-wrap ' + $(this).attr('class') + '"              style="position:relative; display:inline-block; background:url(' + $(this).attr('src') + ') no-repeat center center; width: ' + $(this).width() + 'px; height: ' + $(this).height() + 'px;" />';     });     $(this).css("opacity","0"); }); 

});

easy peasy, replace $("img") different selector run "wrapping" code on different set of images rather images on site. example use $(".extra img") target img inside tag class "extra" (class="extra").

it's basic, trivial knowledge of jquery - advice read through jquery tutorials or better yet, use jquery code school http://try.jquery.com/ learn how use jquery.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -