Reputation: 637
How to get Descriptions
name if we click on <img src="../Images/Checkmark.ico"
<li id="liRightDescriptions" style="display: list-item;">
<span><span>Descriptions</span>
<img src="../Images/Checkmark.ico" class="checkImage"></span>
</li>
i tired this :-
$('.checkImage').live('click', function (event) {
debugger;
event.preventDefault();
var name = $(this).prev().html();
Upvotes: 0
Views: 108
Reputation: 5993
That would likely work, except you have no closing / in your image, and perhaps more. By the way... using .click() is slower than using .on() ...and .live() is depreciated.
I got it working, so here's a fixed fiddle for you:
http://jsfiddle.net/digitalextremist/QT66f/
Basically the same, but I removed things you may not actually need. Re-add them if you do.
$('.checkImage').on('click', function (event) {
var name = $(this).prev().html();
alert( name )
})
And the HTML:
<li id="liRightDescriptions" style="display: list-item;">
<span>
<span>Descriptions</span>
<img src="../Images/Checkmark.ico" class="checkImage" />
</span>
</li>
Upvotes: 0
Reputation: 14023
try this
$('.checkImage').click(function() {
var name = $(this).prev().html();
});
Upvotes: 0
Reputation: 15616
The live()
function is deprecated and has been replaced with on()
, use:
$('body').on('click', '.checkImage', function(){
var text = $(this).prev('span').text();
});
Upvotes: 0
Reputation: 10653
you should probably use the .siblings()
selector ( http://api.jquery.com/siblings/ )
as an example :
$('.checkImage').live('click', function (event) {
var name = $('.checkImage.').siblings('span').html();
}
Upvotes: 0
Reputation: 7954
Dont use live
its depreciated
$('body').delegate('.checkImage','click',function(){
alert($(this).prev().html());
});
Upvotes: 0
Reputation: 4094
Try:
$('.checkImage').click( function () {
var name = $(this).prev().html();
alert(name)
})
Upvotes: 1