0

I do not have much experience with jQuery and I think this is very minor issue. I am trying to get html of an element including its self. But it is returning only internal content of selected element. For example I have implemented this on litag but I am able to get its internal content only with this. How I can get complete html For example this is my html

<li class="selected_li"> <span> some text </span> </li>

and this is jQuery

 jQuery(".selected_li").html();

So it is returning only span and its text but I want to get complete html which is

<li class="selected_li"> <span> some text </span> </li>

How I can get this. Is there a different jQuery function to get this?

wpdd
  • 416
  • 3
  • 15

1 Answers1

0

You can get it using outerHTML

 console.log($(".selected_li")[0].outerHTML)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li class="selected_li"> <span> some text </span> </li>
</ul>
Amit Kumar
  • 5,888
  • 11
  • 47
  • 85