...

View Full Version : Backcolor changing. Simple stuff.



ktelfon
09-28-2011, 12:19 PM
So how do i get to backgroundColor value to change it?

a.backgroudColor('black');

or how ?




var a = makeDiv(p.age , {
backgroundColor: 'gray',
color: 'white',
padding: '2px 6px',
fontSize: '15pt',
});

jassi.singh
09-28-2011, 01:03 PM
div#nav a {
display:block;
color:#1084aa;
text-decoration:none;
padding:.3em 1em;
margin:0 0 2px;
font:1.2em bold;
text-align:center;
}

div#nav a:hover {
color:#000000;
background-color:#1084AA;
}



<a href="#" onclick="changeTab('home','hcontent');" id="home">Home</a>
var lastTab = "home";
function changeTab(tab,section){
document.getElementById(lastTab).innerHTML =
document.getElementById(lastTab).style.color="#1084AA";
document.getElementById(tab).style.backgroundColor="#1084AA";
document.getElementById(tab).style.color="#000000";
lastTab = tab;
document.getElementById('content').innerHTML = document.getElementById(section).innerHTML;
}

Kor
09-28-2011, 01:07 PM
It depends on how the function makeDiv() looks like. Show us. For the moment we see no constructor there, so that we don't know if the variable a is an object or not.

ktelfon
09-28-2011, 01:19 PM
It depends on how the function makeDiv() looks like. Show us. For the moment we see no constructor there, so that we don't know if the variable a is an object or not.


var makeDiv = function(str, style) {

var div = $('<div>');
div.css(style);
div.text(str);
return div;
};

Kor
09-28-2011, 01:55 PM
If so:


a[i].style.backgroundColor='black';

If I am right, the function returns a collection of all the elements with the tag name DIV, thus you need also an index [i], to refer a singular element.

ktelfon
09-28-2011, 07:29 PM
Okey i think i didnt show all that is needed so you can help me )




var makeDiv = function(str, style) {

var div = $('<div>');
div.css(style);
div.text(str);
return div;
};

var makeP = function(p) {

var a = makeDiv(p.name + ' ' + p.surname, {
backgroundColor: 'gray',
color: 'white',
padding: '2px 6px',
fontSize: '14pt',
});

var setS = function(newS){
sa = newS;
if (s > 0) {
a.style.backgroundColor = 'yellow'; //this part or something else dosnt work
} else {
s = 0;
a.style.backgroundColor = 'gray';
}
}




I tried this

$('div#d').css('background-color','yellow');
but div tags dont have an id so i can change all of them but how do i change a specific one ? maybe there is a way to adjust the div creator so it has not only style and text but also an ID.

Kor
09-29-2011, 11:30 AM
but div tags dont have an id so i can change all of them but how do i change a specific one ?
If it is a specific one, what makes it specific? Is it something which makes that div unique? You need that to refer it.

DOM Elements can be referred:
- by their id
- by their name, in which case one of them can be refereed by its index within the collection. Anyway, not all the DOM elements are entitled to bear a name.
- by their tag name, in which case one of them can be refereed by its index within the collection
- by their class name, in which case one of them can be refereed by its index within the collection
- by their DOM relationship: parent, child, siblings.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum