You can target an HTML element using JavaScript by using the document.getElementById()
method, which returns an element object with the specified ID.
For example:
<div id="myDiv">This is a div element.</div>
<script>
var myDiv = document.getElementById("myDiv");
console.log(myDiv.innerHTML);
// Output: "This is a div element."
</script>
Alternatively, you can use other methods like document.querySelector()
or document.getElementsByClassName()
, depending on your selection criteria.
+ There are no comments
Add yours