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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do I add background color change for this function?

    Hello,
    this is a short post. Please help if you can.
    I have the following function that effects cells according to a defined array by changing the size of the image. I would like to keep the array idea but include a background change. The height and width i would just remove, i'm basically trying to highlight cells, and this function is perfect other than the fact im not sure how to add a background color change.

    Code:
    function showImg(info) {
       var images = document.getElementById('tbl').getElementsByTagName('img');
       var sel = ptrArray[info].slice(0);  // alert(sel);
       for (var i=0; i<sel.length; i++) {
         images[sel[i]].style.height = "100px";
         images[sel[i]].style.width = "75px";
    
       }
    Thankyou in advance.

  • #2
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Should just be

    images[sel[i]].style.background = "yellow";


    HTH
    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #3
    Senior Coder jerry62704's Avatar
    Join Date
    Oct 2007
    Location
    Springfield, IL
    Posts
    1,100
    Thanks
    13
    Thanked 87 Times in 87 Posts
    Code:
    function showImg(info) {
       var images = document.getElementById('tbl').getElementsByTagName('img');
       var sel = ptrArray[info].slice(0);  // alert(sel);
       for (var i=0; i<sel.length; i++) {
         images[sel[i]].style.height = "100px";
         images[sel[i]].style.width = "75px";
    
       }
    If you are getting the element by ID which is unique, why do you also need the tag name? Is it because you have multiple elements under the ID? Your code could help resolve such questions.
    .
    .
    ...and gladly would he learn and gladly teach

    Visit www.LiberalsWin.com for humor and the unique Bush/Obama Approval Polls


  •  

    Posting Permissions

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