I have a webpage. Suppose I don't know that the page contains a <p>
or any other HTML tag. The script runs in the background and when I click anywhere on the webpage if there is a corresponding HTML tag to the click then the script returns the tag with its index number.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<p></p>
<div></div>
<div></div>
</body>
</html>
Now when I click on the tag p then the script should return <p>
and its index. Somewhat like this:
$("body").click(function(){
/* return the clicked html tag within body and its index*/
});
For this:
$("tag name").click(function(){
// return tag
});
I need to know which tag I am clicking on. But I don't know on which tag I'm going to click.
Pure JS will also do.
` in a paragraph, wrap them in backticks. This question made little sense prior to my edit, because these tags were rendered as HTML, not text. I recommend using the preview window when composing a post here - it means you can check what your post will look like even before it has been submitted.
– halfer Oct 03 '18 at 09:52