Saturday, April 4, 2015

Get selected element's outer HTML

<div id="test">
  <p><span>test 1</span></p>
  <p><span>test 2</span></p>
  <p><span>test 3</span></p>
  <p><span>test 4</span></p>
</div>

<script>
  var test1 = $('#test p:nth-last-child(2)')[0].outerHTML;
  var test2 = $('#test p:nth-last-child(1)')[0].outerHTML;

  console.log(test1);
  console.log(test2);
</script>

Reference:

http://stackoverflow.com/questions/2419749/get-selected-elements-outer-html

No comments: