6

I would like to create _blank with js HTML DOM, is it correct?

var a = document.createElement('a');

a.appendChild(document.createTextNode(contacts[i][j]));

a.setAttribute("href","http://www.facebook.com/", contacts[i][j],"target","_blank" );

td.appendChild(a);

2 Answers 2

10

I think you should spilt the setAttribute like:

a.setAttribute('href', 'http://www.facebook.com/');

a.setAttribute('target', '_blank');

According to the docs it takes only two parameters.

Sign up to request clarification or add additional context in comments.

Comments

1

The setAttribute method accept only 2 parameters

  1. name is the name of the attribute as a string.
  2. value is the desired new value of the attribute.

   var a = document.createElement('a');
   a.appendChild(document.createTextNode(contacts[i][j]));
   a.setAttribute('href', 'http://www.facebook.com/');
   a.setAttribute('target', '_blank');
   td.appendChild(a);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.