-1

how to create elements in javascript with href=variable? how to create this with javascript when you click a button? every time you hit the button, another div will appear.

<div><a href=myfirstvariable><img src="mysecondvariable"></a></div>

thanks

Dwadelfri
  • 454
  • 1
  • 4
  • 15
  • What outcome/output do you want? A new `div` to appear (where?) in the page on every click of the `a` element? Or...something else entirely? – David Thomas Nov 17 '13 at 15:44
  • https://developer.mozilla.org/en-US/docs/Web/API/document.createElement , https://developer.mozilla.org/en-US/docs/Web/API/Element.setAttribute – Quentin Nov 17 '13 at 15:45
  • try this: http://stackoverflow.com/questions/4365246/how-to-change-href-of-a-tag-on-button-click-through-javascript – Tomer Amir Nov 17 '13 at 15:45
  • You are asking too many things at once and it is not clear what you have tried so far. – cherouvim Nov 17 '13 at 15:48

1 Answers1

0

Don't know exactly what you want, but you can create an a element with href=variable like this :

var a = document.createElement('a');
a.href = "http://google.fr";
Preview
  • 35,317
  • 10
  • 92
  • 112