JavaScript's method of dynamically modifying the content of web elements

  • 2020-05-17 04:50:17
  • OfStack

This article illustrates how JavaScript dynamically modifies the content of web elements. Share with you for your reference. The specific analysis is as follows:

The JS code below dynamically specifies the content of the element by textContent or innerHTML when the user clicks the submit button


<script type="text/javascript">
function showCard() {
 var message = document.getElementById("CCN").value;
 var element = document.getElementById("mycreditcardnumber");
 element.textContent = message;
//for Firefox
 element.innerHTML = message;
//for IE (why can't we all just get along?)
 return true;
}
</script>
<form name="dynamic" method="get">
<span>Enter Your Credit Card Number:</span>
<input type="text" id="CCN" name="CCN" value="CCN" />
<input type="button" value="submit" onclick="showCard()" />
</form>
<p>Verify your Credit Card Number:
 <span id="mycreditcardnumber">0000-00-0000-00 </span>
</p>

I hope this article has been helpful to your javascript programming.


Related articles: