Why this does not work in IE/Chrome but works in FF/Opera? I want to make the div around anchor clickable, so that when you click div, it behaves the same as if you would click the anchor itself.
<script src="jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
function bindOnClickPostBack() {
$(".header a").each(function () {
var anchor = $(this);
var clickEvent = anchor.attr('href');
var header = anchor.parent();
header.css('background-color', 'yellow');
header.attr('onclick', clickEvent);
});
/*$(".header").live("click", function(){
anchor = $(this).find('a');
var clickEvent = anchor.attr('href');
alert(clickEvent);
$(this).css('background-color', 'yellow');
//header.attr('onclick', clickEvent);
//anchor.click();
});*/
return false;
}
$(document).ready(function() {
bindOnClickPostBack();
});
</script>
body:
<div style="background-color:red" class="header"> <a href="alert('hello1')">Shortcut1</a></div>
<div style="background-color:red" class="header"> <a href="alert('hello2')">Shortcut2</a></div>
<div style="background-color:red" class="header"> <a href="alert('hello3')">Shortcut3</a></div>
<div style="background-color:red" class="header"> <a href="alert('hello4')">Shortcut4</a></div>