locked
How to dynamically style a listview container class using Javascript? (Windows App)

    Question

  • CSS version: Works just fine

    .win-groupheadercontainer
    {
        left:-30px;    
    }

    Javascript version: I get "Intellisense was unable to determine an accurate completion list for this expression."    querySelector only seems to recognize #listviewId as argument for styling purposes.

    document.querySelector('.win-groupheadercontainer').style.left = "-30px";

    Could someone please tell me what I'm doing wrong here?

    • Edited by AlanSanford Saturday, April 26, 2014 8:23 AM
    Saturday, April 26, 2014 8:07 AM

Answers

  • ".win-groupheadercontainer" is a class, so most likely you are dealing with an array. To style each element in the array, you would use something like a for loop to cycle through the array and set the style.left for each element. Here's some example code:

    var Container = document.querySelector('.win-groupheadercontainer');
    
    for(var i = 0; i < Container.length; i ++){
         Container[i].style.left = "-30px";
    }

    Hope this helps!


    • Proposed as answer by datQkiD2 Saturday, April 26, 2014 4:30 PM
    • Edited by datQkiD2 Sunday, April 27, 2014 4:25 PM
    • Marked as answer by AlanSanford Monday, April 28, 2014 6:15 PM
    Saturday, April 26, 2014 4:30 PM

All replies

  • ".win-groupheadercontainer" is a class, so most likely you are dealing with an array. To style each element in the array, you would use something like a for loop to cycle through the array and set the style.left for each element. Here's some example code:

    var Container = document.querySelector('.win-groupheadercontainer');
    
    for(var i = 0; i < Container.length; i ++){
         Container[i].style.left = "-30px";
    }

    Hope this helps!


    • Proposed as answer by datQkiD2 Saturday, April 26, 2014 4:30 PM
    • Edited by datQkiD2 Sunday, April 27, 2014 4:25 PM
    • Marked as answer by AlanSanford Monday, April 28, 2014 6:15 PM
    Saturday, April 26, 2014 4:30 PM
  • Got it . Thanks a bunch.
    Monday, April 28, 2014 6:18 PM