This is an old revision of the document!


Introduction to JavaScript Workshop

  1. function replaceImagesWithUrl(url) {
  2. // Get all img elements in the document
  3. var images = document.getElementsByTagName('img');
  4.  
  5. // Convert images NodeList to an array and iterate using forEach
  6. Array.from(images).forEach(function(img) {
  7. // Replace the src attribute with the provided URL
  8. img.src = url;
  9. });
  10. }
  1. function replaceSpanText(newText) {
  2. // Get all span elements in the document
  3. var spans = document.getElementsByTagName('span');
  4.  
  5. // Convert NodeList to an array and iterate using forEach
  6. Array.from(spans).forEach(function(span) {
  7. // Replace the text content of the span with the provided new text (string
  8. span.textContent = newText;
  9. });
  10. }
  • intro-to-javascript-wokshop.1720169616.txt.gz
  • Last modified: 4 months ago
  • by renick