Hi,

Please look at this code

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

 //css

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

 //script
 $('.box').click(function(){
    $(this).find('a').trigger('click');
 });

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,
Developer

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>
<html>
<head>
<title>Demo</title>
<style> 
 .box { 
 width:250px; 
 height:250px;  
 border:1px solid red; 
 display:block;
 }
</style>
</head>
<body>
 <a class="box" href="http://www.google.com"  target="_blank">click</a>
</body>
</html>

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">

</div>


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

var href = 'http://www.google.com';
$('.box').click(function(){
 window.location.href= href;   //This should open in target _blank 
});

Is that possible, Hope now question will be clear

Thanks in advance

Developer

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>
</div>

Our target is div should open in new window.

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

http://www.automobilemag.com/auto_shows/

thanks in advance,
Developer

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

$(".article-content").find("a.news-title").attr("target","_blank");

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, networking, learning, and sharing knowledge.