如何获取被点击的html元素并进行编辑?

How to get the clicked html element and edit?

我想获取点击的 html 个元素并在一段时间后对其进行编辑。

我尝试了什么?

我尝试了下面的方法,但我可以得到 html 文本格式的确切 html 元素,但我无法更改它。如何更改值。

var _targetevent;

$( "body" ).click(function( event ) {
  _targetevent=event;
  console.log( "clicked: " + event.target); //<p>This is the old one</p>
});

function undateit()
{
  _targetevent.target="<b>This is the new div</b>";
}

1.Call undateit() 里面 click()

2.Use innerHTML 以及 _targetevent.target

示例:-

var _targetevent;

$( "body" ).click(function( event ) {
  _targetevent=event;
  console.log( "clicked: " + event.target.id); //get id of the clicked element
  undateit(); //call function on click
});

function undateit(){
  //use outerHTML to completly replace div with new-one
  
  _targetevent.target.outerHTML="<b>This is the new div</b>";
  
  /* if you want to change only content inside element then use inner HTML
  
  _targetevent.target.innerHTML="<b>This is the new div</b>"; //use innerHTML
  
  */
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
<div id="mydiv">Check change</div>
</body>