Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Backcolor changing. Simple stuff.

    So how do i get to backgroundColor value to change it?

    a.backgroudColor('black');

    or how ?

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

  • #2
    Regular Coder
    Join Date
    Sep 2011
    Posts
    103
    Thanks
    0
    Thanked 14 Times in 14 Posts
    Code:
    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;
    	}
    Code:
    <a href="#" onclick="changeTab('home','hcontent');" id="home">Home</a>
    Code:
    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;
    }

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #4
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Kor View Post
    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.
    Code:
    var makeDiv = function(str, style) {
     
      var div = $('<div>');
      div.css(style);
      div.text(str);
      return div;
    };

  • #5
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    If so:
    Code:
    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.
    Last edited by Kor; 09-28-2011 at 01:58 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #6
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    5
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Okey i think i didnt show all that is needed so you can help me )

    Code:
    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
    Code:
    $('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.
    Last edited by ktelfon; 09-29-2011 at 07:30 AM.

  • #7
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Quote Originally Posted by ktelfon View Post
    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.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •