Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #31664

Re: How to replace a class?

Newsgroups comp.lang.javascript
Date 2016-11-10 11:58 -0800
References <5a64eafc-a7f3-44e2-88ce-fe388101ecba@googlegroups.com> <XnsA6BB50B9C4B39eejj99@194.109.6.166> <28c08bf8-fb92-4487-acd1-10f9ea445d16@googlegroups.com> <bd5236f5-a271-4e96-89a9-590d490b49f8@googlegroups.com>
Message-ID <cc2892c6-e51d-4e61-862f-53a66d842194@googlegroups.com> (permalink)
Subject Re: How to replace a class?
From justaguy <lichunshen84@gmail.com>

Show all headers | View raw


On Thursday, November 10, 2016 at 1:08:07 PM UTC-5, Ram Tobolski wrote:
> >Then, there would variable length of such elements, how do I replace all the elements with class name of "Space" with another class?
> 
> Like this?
> 
> let elements = document.getElementsByClassName("Space");
> elements.forEach(element => element.className = newClass);

Promising.  dev mode / debugging mode with Chrome seems to indicate correct is correct, however, the replaced element were not rendered with the Chrome browser.

Here's the entire code:

// global var to hold elements for multiple functions
var elS = [];

var addPC = function() {
	var el = document.createElement("span");
	el.innerHTML = "<img src='pc.png'>";						
	document.body.appendChild(el);
	
	// add some space
	var sp = document.createElement("span");
		sp.className = "Space";
		/*
		sp.style.width = "15px";
		*/
		sp.innerHTML = "<img src='spacer.png' border=0>";
	document.body.appendChild(sp);	
							
	// send to global elS as well
	elS.push(sp);
	
} 
			
var connector = function() {

// define line class
	let lineC = document.getElementsByClassName('Line');
		lineC.innerHTML = "<img src='line.png'>";

// debug
	console.log(elS);
	
// replace class
elS.forEach(el => (el.className = "Line")); 
// elS.forEach(el => (el.innerHTML = "<img src='line.png' border=0")); 
	
}	

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

How to replace a class? justaguy <lichunshen84@gmail.com> - 2016-11-08 18:53 -0800
  Re: How to replace a class? justaguy <lichunshen84@gmail.com> - 2016-11-10 07:45 -0800
    Re: How to replace a class? Ram Tobolski <ramtob@gmail.com> - 2016-11-10 10:08 -0800
      Re: How to replace a class? justaguy <lichunshen84@gmail.com> - 2016-11-10 11:58 -0800
        Re: How to replace a class? justaguy <lichunshen84@gmail.com> - 2016-11-10 13:06 -0800
          Re: How to replace a class? Ram Tobolski <ramtob@gmail.com> - 2016-11-10 13:37 -0800
            Re: How to replace a class? justaguy <lichunshen84@gmail.com> - 2016-11-10 14:09 -0800
              Re: How to replace a class? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-11-11 00:01 +0100
          Re: How to replace a class? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-11-10 22:51 +0100
            Re: How to replace a class? justaguy <lichunshen84@gmail.com> - 2016-11-10 14:09 -0800
        Re: How to replace a class? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-11-10 23:20 +0100
          Re: How to replace a class? John Harris <niam@jghnorth.org.uk.invalid> - 2016-11-11 10:24 +0000
            Re: How to replace a class? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-11-11 12:37 +0100
              Re: How to replace a class? John Harris <niam@jghnorth.org.uk.invalid> - 2016-11-12 17:09 +0000
          Re: How to replace a class? John Harris <niam@jghnorth.org.uk.invalid> - 2016-11-11 10:41 +0000
            Re: How to replace a class? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-11-11 12:43 +0100
              Re: How to replace a class? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-11-11 14:52 +0100
                Re: How to replace a class? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-11-11 15:11 +0100
                Re: How to replace a class? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-11-11 15:30 +0100
                Re: How to replace a class? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-11-11 16:41 +0100
                Re: How to replace a class? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-11-11 23:54 +0100
              Re: How to replace a class? John Harris <niam@jghnorth.org.uk.invalid> - 2016-11-12 18:42 +0000
            Re: How to replace a class? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-11-11 14:46 +0100
              Re: How to replace a class? John Harris <niam@jghnorth.org.uk.invalid> - 2016-11-12 14:51 +0000
                Re: How to replace a class? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-11-12 20:13 +0100
                Re: How to replace a class? justaguy <lichunshen84@gmail.com> - 2016-11-12 11:35 -0800
                Re: How to replace a class? John Harris <niam@jghnorth.org.uk.invalid> - 2016-11-13 11:13 +0000
      Re: How to replace a class? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-11-10 23:11 +0100
        Re: How to replace a class? justaguy <lichunshen84@gmail.com> - 2016-11-10 15:08 -0800
    Re: How to replace a class? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-11-10 20:37 +0100
      Re: How to replace a class? justaguy <lichunshen84@gmail.com> - 2016-11-10 11:59 -0800
        Re: How to replace a class? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-11-10 21:01 +0100

csiph-web