[wd_asp elements=’search’ ratio=’100%’ id=1]

Get ID or SRC of Closest Div or LI

12th June 2014

Jquery - Variables

jquery icon

This id
var thisid = $(this).attr("id");

This first one gets the id of the closest li
var thetext = $(this).closest("li").attr("id");


This will start from where clicked, and go up to the first .mybutton, then find .fakes class inside.
var thetext = $(this).closest('.mybutton').find(".fakes").html();


Get the image url value from class name
var thetext = $(this).closest('.deleteitem').find(".item").attr('src');

Get the image name/src/alt tag from an image inside a class

P1080317.JPG



var dog = $( '.dz-image > img' ).attr( 'alt' );
alert(dog);


Hides the closest element with the classname .deleteitem

$(this).closest('.deleteitem').hide();


Affect the opacity of an image

$(this).closest('.deleteitem').css({"opacity":"0.4"});


This snippet will find the clicked elements – next elements class called “.item” and get the src the image with that class name!
theimagename = $(this).next().find('.item').attr('src');
alert(theimagename);

Get ID of next DIV up

var id = $(".button").closest("div").prop("id");
alert(id);