1

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?

royhowie
  • 11,075
  • 14
  • 50
  • 67
user1835427
  • 13
  • 1
  • 3

4 Answers4

5
$("#whole").click(function () {
   window.open($(this).attr("href"), '_blank');
});
davids
  • 6,259
  • 3
  • 29
  • 50
3

You need window.open

window.open($(this).attr("href"))
Adil
  • 146,340
  • 25
  • 209
  • 204
0
$(document).ready(function() {
$("#whole").click(function () {
    window.open("href"); // window.open('https://stackoverflow.com/questions/13452398/jquery-how-to-make-a-clickable-div-open-in-a-new-window');
    });
});
BeardedPrince
  • 210
  • 2
  • 8
0

You can do by following method

1)

 $(document).ready(function() {
$("#divId").click(function () {
window.open("openThisPage.html"); //Change 'openThisPage.html' to your target page
});
});