current element html in jquery

outerHTML and innerHTML

If you want to get html of current element you have to use outerHTML of JavaScript. jQuery not provide any function which retrun outHTML of element but jQuery provide html() function which return innerHTML of current element.

outerHTML means html with current element and innerHTML means html without current element. If you get table html with the help of html() function of jQuery it return all tbody of that table not current table.

As we know that if we use [0] after selector it return DOM element not jQuery object, so after getting DOM element you can use outerHTML or innerHTML.


<!DOCTYPE html>
  <title>jQuery With Example</title>
  <script src="" type="text/javascript"></script>
  <script type="text/javascript">
    $(function () {
      $('.btnOuterHtml').click(function () {

      $('.btnInnerHtml').click(function () {

  <div class="Container">
     <table class="tblCountry" border="1" cellspacing="0" cellpadding="5">
        <tr><td>Country Id</td><td>Country Name</td></tr>
    <button type="button" class="btnOuterHtml">Get Outer Html</button>
    <button type="button" class="btnInnerHtml">Get Inner Html</button>
Country IdCountry Name

No comments :

Please Give Your Feedback