if i have this html
<div class="whole">This is a <div class="min">Test</div></div>
i want to change the html of the “whole” div when i click on the “min” div:
i have tried this below, but it doesn’t seem to work.
$(document).ready(function() {
$('div.min').live('click', function() {
$(this).prev('.whole').html("<img BORDER=0 src='../../images/copy1.png' />");
});
});
does anyone have any ideas on whats going wrong here ?
You want
parent, notprev. Yourdiv.minis inside, not next to, thediv.whole. So:2017 update:
livehas been deprecated for years and was eventually removed. It’s used in the above because it was in the OP’s original code and wasn’t the issue, but just for completeness, the current way to do this is withon‘s delegation signature:Note that we don’t even need the
ready, since this is doing event delegation ondocument, so it doesn’t have to wait. (That was true of theliveversion above as well.)