Search code examples
jquerytarget

jquery how to make a clickable div open in a new window


I want to make a DIV with no content clickable for that I use this jquery code:

<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript">

$(document).ready(function() {
$("#whole").click(function () {
    window.location = $(this).attr("href");
    });
});

</script>

It works fine, but the link always opens in the same window. How do I need to change the code, to make the div open in a new window?


Solution

  • $("#whole").click(function () {
       window.open($(this).attr("href"), '_blank');
    });