Please login to start chat

ICT Solutions 2020-04-24 17:04:37
Category : JavaScript Tutorials

Accessing Elements

// 1. Access Element By Id
/*
function tnwFun(){
var txt = "<b>Welcome to TNW(Web Service & ICT Solutions)</b><br /><br />TNW Provides The Best ICT Solutions For Your Business By The Reasonable Price.";
document.getElementById("tnwId").innerHTML = txt;
}*/

// 2. Access Elements By ClassName

/*
function tnwBlue(){
var i;
var x = document.getElementsByClassName("tnwPage");
for(i = 0; i < x.length; i++){
x[i].style.backgroundColor = "blue";
x[i].style.color = "white";
}
}

function tnwRed(){
var i;
var x = document.getElementsByClassName("tnwPage");
for(i = 0; i < x.length; i++){
x[i].style.backgroundColor = "red";
x[i].style.color = "white";
}
} */

// 3. Access Elements By Name
/*
function tnwBlue(){
var i;
var x = document.getElementsByName("tnwName");
for(i = 0; i < x.length; i++){
x[i].style.backgroundColor = "blue";
x[i].style.color = "white";
}
}

function tnwRed(){
var i;
var x = document.getElementsByName("tnwName");
for(i = 0; i < x.length; i++){
x[i].style.backgroundColor = "red";
x[i].style.color = "white";
}
} */

// 4. Access Elements By tagName
/*
function tnwFun(){
var i;
var x = document.getElementsByTagName("li");
for(i = 0; i < x.length; i++){
x[i].style.color = "red";
}
}*/

// 5. Access Element By CSS Selector

function tnwFun(){
var i;
var x = document.querySelectorAll(".tnwClass");
for (i = 0; i < x.length; i++){
x[i].style.color = "red";
}
}

To see video in YouTube.

Comments:

No comment to show.

Available Services
Download Android Application