Avatar of SMabs
SMabs

asked on 

Javascript : Cycle Div IDs w/Prefix & Reset HTML

I need a simple snippet to cycle through all the DIVs in a document with the ID prefix of "VALIDATIONRESPONSE." and reset the internal HTML

So there could be 10 DIVs with unique names like "VALIDATIONRESPONSE.email_addr" and "VALIDATIONRESPONSE.first_name"

I need a JS snippet to cycle through the Document that resets the Internal HTML of each div to NULL (empty)

JavaScriptAJAXJScript

Avatar of undefined
Last Comment
SMabs
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of SMabs
SMabs

ASKER

the ID of the DIVs is VALIDATIONRESPONSE.  not the content...


example:  <div id="VALIDATIONRESPONSE.email_addr"></div>

Avatar of SMabs
SMabs

ASKER

Here, I just modified your code.. the basics were there.

switched out innerHTML for id

Thanks :)


            var divs = document.getElementsByTagName("div");
            for(var i=0;i<divs.length;i++) {
                  var b = divs[i].id.indexOf("VALIDATIONRESPONSE.")>=0;
                  if(b) {
                        divs[i].innerHTML = "";
                  }
            }
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Test page :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript">
	window.onload= function() {
		var divs = document.getElementsByTagName("div");
		for(var i=0;i<divs.length;i++) {
			var b = divs[i].id.indexOf("VALIDATIONRESPONSE")>=0;
			if(b) {
				divs[i].innerHTML = "";
			}
		}
	}
</script>
</head>
<body>
<div id=VALIDATIONRESPONSE.email_addr" >SOME TEXT</div>
<div id=VALIDATIONRESPONSE.first_name" >SOME TEXT</div>
<div id=VALIDATIONRESPONSE.email_addr1" >SOME TEXT</div>
<div id=VALIDATIONRESPONSE.first_name1" >SOME TEXT</div>
<div id=VALIDATIONRESPONSE.email_addr2" >SOME TEXT</div>
<div id=VALIDATIONRESPONSE.first_name2" >SOME TEXT</div>
<div id=ALIDATIONRESPONSE.email_addr3" >SOME TEXT</div>
<div id=VALIDATIONRESPONSE.first_name3" >SOME TEXT</div>
<div id=VALIDATIONRESPONSE.email_addr4" >SOME TEXT</div>
<div id=VALIDATIONRESPONSE.first_name4" >SOME TEXT</div>
<div id=VALIDATIONRESPONSE.email_addr5" >SOME TEXT</div>
<div id="ALIDATIONRESPONSE.first_name5" >SOME TEXT</div>
<div id=VALIDATIONRESPONSE.email_addr6" >SOME TEXT</div>
<div id=VALIDATIONRESPONSE.first_name6" >SOME TEXT</div>
<div id=VALIDATIONRESPONSE.email_addr7" >SOME TEXT</div>
<div id="ALIDATIONRESPONSE.first_name7" >SOME TEXT</div>
<div id=VALIDATIONRESPONSE.email_addr8" >SOME TEXT</div>
<div id=VALIDATIONRESPONSE.first_name8" >SOME TEXT</div>
<div id="ALIDATIONRESPONSE.email_addr9" >SOME TEXT</div>
<div id=VALIDATIONRESPONSE.first_name9" >SOME TEXT</div>
</body>
</html>

Open in new window

Avatar of leakim971
leakim971
Flag of Guadeloupe image

You're welcome! Thanks for the points!
Avatar of SMabs
SMabs

ASKER

if you would like to take a stab at the other question I have open.. the SWITCH string comparison issue... I need it solved.
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo