Please look at this code

 <div class="box">
 <a href="http:www.google.com"  target="_blank">click</a>


 .box { width:250px; height:250px;  border:1px solid red; }


How to set target _blank when clicking the div.box.
click is working fine but it opens the page in same window.

Can you anyone have idea..

Thanks in advance,

Recommended Answers

All 11 Replies

Your href value is incorrect, it should start http://

You don't need the JS to open a new window the (deprecated) target atrribute should take care of that for you.

So, as you can see we are a bit confused as to this approach. If you can provide clarification on what you are trying to implement, better guidance can be provided.

If you are simply trying to create a box that acts like a link, try this approach. Simply use an anchor element, but style it with display:block. See this example..

<!DOCTYPE html>
 .box { 
 border:1px solid red; 
 <a class="box" href="http://www.google.com"  target="_blank">click</a>

This approach creates the look and feel as your sample code, but without the div element and the _blank works as expected.

Hope this helps..

Hi thanks for all,

I am not trying to create a box, Its like a article section.
What we will do is, we will get the article link and append to the parent div(.box) so ultimately it works.But target is not working.

Let me ask you straightly

<div class="box">


.box { width:250px; height:250px; border:1px solid red; }

var href = 'http://www.google.com';
 window.location.href= href;   //This should open in target _blank 

Is that possible, Hope now question will be clear

Thanks in advance


Hi paulkd,

I understand that, but our requirement is like that.

Our format should be like this and we say it like "Obfuscation"

<div class="box">
< a href="http://www.google.com"></a>

Our target is div should open in new window.

Please check the article section in the link, I hope you can understand


thanks in advance,

Is it the <a class="article-top" /> that you will be targeting?

Dear paulkd,

Please check out the link,
I am targeting the below div, link should be inside the div with class .news-title and it should open in new window.

<div class="article-content"></div>

I think you might just be able to add


to your js file.

But I would be wrong :(

So I think you are left with using window.open. Is this allowed?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.