What's wrong with this JavaScript code? -


var allhtmlelements = document.body.getelementsbytagname("*"); (var = 0; < allhtmlelements.length; i++) {     if (allhtmlelements[i].getattribute("group") && allhtmlelements[i].getattribute("index")) continue;     allhtmlelements[i].style.color = "red"; } 

<div group="mygroup">hello</div> <div>hello</div> <div index="d534">hello</div> 

all divs turn red , ones group , index not stay default color. middle should turn red doesn't.

the problem you're using && when should using ||

if (allhtmlelements[i].getattribute("group") || allhtmlelements[i].getattribute("index")) continue; 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -