-1

Edit:

sorry for bad explanation so i have:

 var x = $("span", this).get( 0 );
 var y = x.outerHTML 

and it give me: <span>'some text'</span> but i want just only tag <span></span> with all atributes. My question is how to get it?;p

thanks for any help!

Puki
  • 21
  • 3

2 Answers2

0

The problem in your code: var x = $("span", this).get( 0 ); <-- you have parent (even TAG name) and taking first child var y = x.outerHTML <-- here you're trying to get parent (you eant - TAG name) :%

So, if you know var x = $("span"... <---- this string - you can easily create a string you want

var tag = "span";
var x = $(tag, this).get( 0 );
var y = x.outerHTML;
// the most dumbest way
var result = '<'+tag+'>'+'<'+tag+'/>';
Shulyk Volodymyr
  • 767
  • 6
  • 11
0

cloneNode() by default does not copy the element content, so you can use it:

var x = $("span", this).get( 0 );
var y = x.cloneNode();
var z = x.outerHTML;

In your function of fiddle it would be something like that:

var x = tur.cloneNode();
console.log(x.outerHTML);
Ruslan Batdalov
  • 793
  • 1
  • 8
  • 21