How to Implicitly mimic click() in jQuery?

jQueryWeb DevelopmentFront End Technology

To implicitly mimic click(), you can call a function internally.


Following is the code to implicitly mimic click −

 Live Demo

<!DOCTYPE html>
<html lang="en">
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="//">
<script src=""></script>
<script src=""></script>
   <div id='demo1'>My Name is John Doe</div>
   <div id='demo2'></div>
   <div id='output'></div>
   demo1Data = document.getElementById('demo1').innerHTML
   demo1Data = demo1Data.replace('My Name is John Doe', `<span onclick="replaceData()">My Favourite Subject is JavaScript..</span>`)
   document.getElementById('demo2').innerHTML = demo1Data
   function replaceData() {
      document.getElementById('output').innerHTML = 'I live is US.';

To run the above program, save the file name anyName.html (index.html). Right click on the file and select the option “Open with Live Server” in VS Code editor.


The output is as follows −

Published on 03-Oct-2020 16:27:04