JSFiddle - React, Tailwind, and code Playground

Bosquejo de como obtener el padre apartir de un id hijo jquer

by Raul Corona Xolaltenco

HTML

<div id="resultado"></div>
<button>Set background-color</button>

<div style="border:1px solid black;width:70%;position:absolute;left:10px;top:50px">
<div style="border:1px solid black;margin:50px;background-color:yellow">

<p>Click button to set the background color of the first positioned parent element of this paragraph.</p>

</div></div>

<table border="1">
<tr id="uno">
<td>
elemento
</td>
</tr>
</table>

JavaScript

$("button").click(function(){
    //$("p").offsetParent().css("background-color","red");

   if(typeof $("#uno").parent().parent().attr('id')==="undefined") 
      $("#uno").parent().parent().attr('id', 'latabla');  
  $("#latabla >tbody > tr ").after('<tr><td>'+$("#latabla >tbody > tr").length+'</td></tr>');
  
$("#resultado").html($("#latabla > tbody > tr").length);
//alert($("#uno").parent().parent().get(0).tagName);
//alert($("#uno").parent().parent().attr('id'));
//alert($("#latabla > tbody > tr").length);


  });