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
  • 10,805
  • 14
  • 48
  • 67
user1835427
  • 13
  • 1
  • 3

4 Answers4

4
$("#whole").click(function () {
   window.open($(this).attr("href"), '_blank');
});
davids
  • 6,049
  • 3
  • 27
  • 46
3

You need window.open

window.open($(this).attr("href"))
Adil
  • 143,427
  • 25
  • 201
  • 198
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
  • 180
  • 1
  • 7
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
});
});