How to open a link in new tab using <a> tag in javascript and jquery

<>

This question already has an answer here:

Answers


Using jQuery: (Given that there is an <a> element present)

$(function(){
   $('a').attr('target', '_blank').attr('href', 'YOUR_LINK').trigger('click')
});

EDIT

Another case (You have <div> element and you want to append a link inside it);

$(function(){
   $('div').append('<a href = "YOUR_LINK" target = "_blank">LINK</a>');
});

You just need to add like below, and it will work

<a href="URLValue" target="_blank" >My link</a>

Jquery code:-

$(this).find("a").attr("target", "_blank");

Need Your Help

Symbol to method call

ruby

Is there a way to transform a symbol to a method call? I know it's possible for a String, but not for a symbol. I have this code in conveyance.rb:

rubymine - Could not find gem “jquery-rails”

ruby rubymine

I have installed rubymine and Ruby193 (with rubyinstaller).

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.