954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How do I change CSS properties with javascript?

i'm novice to this and can anybody say how to change CSS properties with javascript functions?
how can i change font-sizes/font styles using a combobox represented in a textarea?
[img]http://i.imgur.com/KH0om.jpg[/img]
if you can show me how events working..thank you

divsok
Light Poster
27 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

It's much easier if you use the jQuery library.

stbuchok
Master Poster
730 posts since May 2011
Reputation Points: 120
Solved Threads: 93
 

I agree with stbuchok, if you would like it more simple, jQuery's .css() is very easy to implement. Here is a link: http://api.jquery.com/css/

suhaildawood
Newbie Poster
18 posts since Feb 2011
Reputation Points: 10
Solved Threads: 3
 
<!doctype native>
<html>
<head>
</head>
<body>
Font Size: <select id=fontSize>
             <option>10pt</option>
             <option>12pt</option>
             <option>14pt</option>
           </select>

Font Family: <select id=fontFamily>
               <option>Arial</option>
               <option>Verdana</option>
               <option>Georgia</option>
             </select>

<div id=myDiv> some div </div>
<textarea id=myTextArea> some text content </textarea>

<script>

fontSize.onchange=fontFamily.onchange=setTarget;
setTarget=[myDiv,myTextArea/*etc*/];

function setTarget(x){
	for(x in setTarget)
		setTarget[x].style[this.id] = this.value;
	}
</script>
</body>
</html>
Troy III
Practically a Master Poster
609 posts since Jun 2008
Reputation Points: 120
Solved Threads: 80
 

Thanks..but in this i can't see CSS and events are not working as you've coded.where is the wrong?

divsok
Light Poster
27 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

you are not meant "to see CSS" and the wrong is your lack of copy-paste skill probably [!]
the code works perfectly in all browsers including the ones that are to be invented in the future.
and
what do you mean "events are not working as you've coded"? how "else" are they supposed to work? the other way around?

Troy III
Practically a Master Poster
609 posts since Jun 2008
Reputation Points: 120
Solved Threads: 80
 

sorry for my remissness friend.i checked in HTMLPad 2011 for previews.actually your code is working perfect on browsers..thank you very much.

divsok
Light Poster
27 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 
sorry for my remissness friend.i checked in HTMLPad 2011 for previews.actually your code is working perfect on browsers..thank you very much.


So, what is your problem than?

Troy III
Practically a Master Poster
609 posts since Jun 2008
Reputation Points: 120
Solved Threads: 80
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: