How could I achieve the following: document.all.regTitle.innerHTML = 'Hello World'; Using jQuery where regTitle is my div id?
To achieve the equivalent of document.all.regTitle.innerHTML = 'Hello World';
using jQuery, you can select the element with the regTitle
ID and then set its HTML content using the .html()
function. Here's how you can do it:
html
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<div id="regTitle">Initial Content</div>
<script>
$(document).ready(function() {
$("#regTitle").html("Hello World");
});
</script>
</body>
</html>
In this example:
- The jQuery library is included by adding the script tag to the HTML head.
- The
$(document).ready()
function is used to ensure that the jQuery code executes after the document has loaded. - Inside the
$(document).ready()
function,$("#regTitle")
selects the element with theregTitle
ID. - The
.html()
function is used to set the HTML content of the selected element to"Hello World"
.
When you run this code, the content of the regTitle
div will be replaced with "Hello World".
Comments
Post a Comment