Explore Replacing Element Content
Practice exploring updating HTML element inside content using the html and text methods.
Lab 1: Replacing inner content using html and text methods interactively.

Steps:
-
Open the html-text-replace.html file in the web browser, open the Elements window and find the following HTML element.
<p id="content">• • • • •</p>


The remaining steps use the
htmland thetextmethods on the#contentelement. -
Open the Console window and enter the following that uses the
htmlmethod …$('#content').html(Math.random());Review results on web page and in the Elements window.


-
Reload the page and in the Console window enter the following that uses the
textmethod …$('#content').text(Math.random());Review results on web page and in the Elements window.


-
Reload the page and in the Console window enter the following that uses the
htmlmethod …$('#content').html('<b>' + Math.random() + '</b>');Review results on web page and in the Elements window.


-
Reload the page and in the Console window enter the following that uses the
textmethod …$('#content').text('<b>' + Math.random() + '</b>');Review results on web page and in the Elements window.


-
Reload the page and in the Console window enter the following that uses the
textmethod …$('#content').text('Lorem ipsum dolor sit amet, consectetur adipiscing elit. <a href="https://lonhosford.com/" target="_blank">Sed hoc sane concedamus.</a> Duo Reges: constructio interrete. <b>Invidiosum nomen est, infame, suspectum.</b> <mark>Erat enim Polemonis.</mark> <code>Nihil enim hoc differt.</code> Et harum quidem rerum facilis est et expedita distinctio. <a href="http://loripsum.net/" target="_blank">Atqui reperies, inquit, in hoc quidem pertinacem;</a> Sed vos squalidius, illorum vides quam niteat oratio.');Review results on web page and in the Elements window.


-
Reload the page and in the Console window enter the following line that uses the
htmlmethod …$('#content').html('Lorem ipsum dolor sit amet, consectetur adipiscing elit. <a href="https://lonhosford.com/" target="_blank">Sed hoc sane concedamus.</a> Duo Reges: constructio interrete. <b>Invidiosum nomen est, infame, suspectum.</b> <mark>Erat enim Polemonis.</mark> <code>Nihil enim hoc differt.</code> Et harum quidem rerum facilis est et expedita distinctio. <a href="http://loripsum.net/" target="_blank">Atqui reperies, inquit, in hoc quidem pertinacem;</a> Sed vos squalidius, illorum vides quam niteat oratio.');Review results on web page and in the Elements window.


Lab 2: Dynamic updating using html method.

Setup Instructions
Copy all the files from the start-05 folder to the practice folder and replace if necessary.
The lab's completed files can be found in the completed folder.
Steps:
-
Open the replace-html-quote.html file in the web browser, open the Sources window to show the replace-html-quote.js file and the Console window.
Your quote may vary depending on the random
eQuotesarray index generated.
-
In the Elements window expand to view the following element.
<p id="e-quote" class="text-center">• • •</p>
In the Console window enter the following line and observe the changes to the web browser view and the Elements window.
$('#e-quote').html('As a human being, one has been endowed with just enough <strong>intelligence</strong> to be able to see clearly how utterly <em>inadequate</em> that <strong>intelligence</strong> is when confronted with what exists.');

-
DIY: Open the replace-html-quote.js file in your editor and modify to update the
#e-quoteelement using thequotevariable, save and test.console.log(quote);$('#e-quote').html(quote);Your quote may vary depending on the random
eQuotesarray index generated.

