-4

Here is code from Javascript.

pageElement.append($('<h2>').append($('<a>').attr('href', 'http://en.wikipedia.org/wiki/' + page.title).text(page.title)));            

This code will not open in a new window. I want to open it in a new window. What do I need to add to Javascript?

Ele
  • 31,191
  • 6
  • 31
  • 67
Sonia
  • 43
  • 5

1 Answers1

1

Well, the same way as you're setting the attr href

$(link_element).attr('target', '_blank');

As Patrick mentioned:

attr() an object of name-value pairs,

.attr({target:'',href:''}) instead of doing multiple calls
Ele
  • 31,191
  • 6
  • 31
  • 67