-->

Thursday, June 5, 2025

JavaScript Program to Use getElementById and style– DOM Manipulation in JS with Examples --- To hide and show the contents

 

JS DOM programs collection



JS program to show  and hide the content using getElementById (DOM)


<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>hiding and showing the text(toggling)</title>

</head>

<body>

<p id="para1">this is JS code</p>

<button onclick="shText();">click to hide/show</button>

<script>

function shText()

{

                var p;

p=document.getElementById('para1');

if(p.style.display=="none")

{

p.style.display="block";

}

else

{

p.style.display="none";

}

}

</script>

</body>

</html>


Output:














JavaScript Program to Use getElementById and oninput event– DOM Manipulation in JS with Examples --- to count total characters entered by user

 

JS DOM programs collection


 JS program to show the concept of getElementById (DOM)



<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>counting typed characters</title>

</head>

<body>

Enter your text<br>

<textarea id="messagecount" oninput="charasCount();" rows="10" cols="10"></textarea>

<p>total characters you have types is:<span id="total">0</span></p>

<script>

function charasCount()

{

var i;

i=document.getElementById('messagecount').value;

document.getElementById('total').innerText=i.length;

}

</script>

</body>

</html>


Output:-

JS program to count total characters



JavaScript Program to Use getElementById – DOM Manipulation in JS with Examples-to change the background color

 

JS DOM programs collection

 JS program to show the concept of getElementById(DOM)


<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>background change</title>

</head>

<body>

<button onclick="colorChange();">click to change the background</button>

<script>

function colorChange()

{

document.body.style.backgroundColor="orange";

}

</script>

</body>

</html>

Output:

JS program to change background color



JavaScript Program to Use getElementById – DOM Manipulation in JS with Examples

JS DOM programs collection


 JS program to show the concept of getElementById(DOM)



<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>background change</title>

</head>

<body>

<button id="bt1" onclick="colorChange();">click to change the background</button>

<script>

function colorChange()

{

//var id=document.getElementById('bt1');

//OR

document.getElementById('bt1').style.backgroundColor="purple";

}

</script>

</body>

</html>


Output:

JS code to implement DOM in program-document.getelementById()



Wednesday, June 4, 2025

c program to concatenate two strings | 2D strings examples in c | program without strcat()

Array and string programs in C

 // program to concatenate two strings without using strcat()

#include<stdio.h>

int main()

{

char string1[100],string2[100];

int i=0,j=0;

printf("enter first string");

gets(string1);

printf("enter second string");

gets(string2);

while(string1[i]!='\0')

{

i++;

}

while(string2[j]!='\0')

{

string1[i]=string2[j];

i++;

j++;

}

string1[i]='\0';

printf("the concatenated string=%s",string1);

return 0;

}


output:-

c program to concatenate two strings without strcat()







c program to count total characters present in a strings | 2D strings examples in c

Array program collection C 


/* program to store multiple strings and count  total their characters

*/

#include<stdio.h>

int main()

{

char string[5][100]={"c program","C++ code","JS code","php code","java code"};

int i,j,count;

for(i=0;i<=4;i++)

{

count=0;

for(j=0;string[i][j]!='\0';j++)

{

count++;

}

printf("the string is %s and its length is %d\n",string[i],count);

}

return 0;

}

Output:

c program to count total letters present in strings