JavaScript How to create a new anchor tag around an existing element

<span class="classname">
<img src="" width="70" height="70">
</span>

I'm trying to add an anchor tag with a URL around the tags. I'm not sure how to do it and I've been stumped for hours..

Answer:1

Try the jQuery .wrap() method,

$("span.avatar").wrap("<a></a>");

Pure JS:

var target = document.getElementsByClassName("avatar")[0];
var wrap = document.createElement("a");

target.parentNode.replaceChild(wrap, target); 
wrap.appendChild(target);
Answer:2

I am creating an ajax slider with only the one "slide" thats data reloads during slide. My current method is to animate the absolute positioned element out of parent viewport, jump to right hand side ...

I am creating an ajax slider with only the one "slide" thats data reloads during slide. My current method is to animate the absolute positioned element out of parent viewport, jump to right hand side ...

What tag is counted in form.elements? <html> <head> <title> form process </title> <script> function showelements() { ...

What tag is counted in form.elements? <html> <head> <title> form process </title> <script> function showelements() { ...

I am trying to load data in JSONStore using loadData method, but it is only loading single record in store. Here is code snippet var myRecord = Ext.data.Record.create([ { name: 'Rid', ...

I am trying to load data in JSONStore using loadData method, but it is only loading single record in store. Here is code snippet var myRecord = Ext.data.Record.create([ { name: 'Rid', ...

  1. extjs jsonstore load data
  2. extjs store loaddata
  3. extjs store loaddata callback
  4. extjs store loaddata not working
  5. extjs store loaddata example
  6. extjs store loaddata event

My Website here I have a page About Us due to lack of content we can not cover the complete height of the screen. And my footer starts floating in the air.. I tried doing it using min-height in a ...

My Website here I have a page About Us due to lack of content we can not cover the complete height of the screen. And my footer starts floating in the air.. I tried doing it using min-height in a ...

  1. make body height 100
  2. make body height of content
  3. make body height 100 css
  4. make height of body css
  5. bootstrap make body height 100
  6. css make body height of window
  7. html make body height 100
  8. make div body height
  9. make div fill body height