Yep, it's me again :)
I want to put the src of an image indise a div on double-click.
Here is how it is:
<div class="explorer_icon"><img src="here.png"/></div>
When we double-click on the div, the src of the image is returned.
How ca开发者_JS百科n i do that?
Here is what i tried, no success, as you can guess.
$('div.explorer_icon').dblclick(function() {
editor($(this).attr('img src'));
});
$('div.explorer_icon').dblclick(function() {
editor($(this).attr('src'));
});
$('div.explorer_icon').dblclick(function() {
editor($('img').attr('src'));
});
Can you help me on this please? Thank you!
Traverse down from the div and get the image, then get it's src attribute.
$('div.explorer_icon').dblclick(function(){
editor($(this).children('img').attr('src'));
});
Need to remember that within your even $(this)
is the div. Since the image resides within it (is a child) you need to locate it, then grab it's attribute.
Try something like this:
Javascript:
$('#test img').dblclick(function() {
$(this).parent().append($(this).attr('src'));
});
HTML:
<div id="test">
<img src="http://sstatic.net/stackoverflow/img/apple-touch-icon.png" />
</div>
精彩评论