0

I have just created a sample grid application using html5 and JavaScript.

What now I want to achieve is to give some animation when user click on group header.

For that I wrote two functions. One for mousedown event and one for mouse up event:

function animateDown() {
    WinJS.UI.Animation.pointerDown(this);
}
function animateUp() {
    WinJS.UI.Animation.pointerUp(this);
}

Now I want add these functions to event listeners for each header. There are many groups headers and they don't have any ids, just classnames.

So how can I add an eventlistener for all the headings?

1 Answer 1

1

You need to use event delegation. So if all elements are in a container you can do:

function toggle(event) {
   var header = event.target;
   if (header.classList.toggle("open") {
      WinJS.UI.Animation.pointerDown(header);
   } else {
      WinJS.UI.Animation.pointerDown(header);
   }
}

document.querySelectorAll(".container").addEventListener("click", toggle, false); 
Sign up to request clarification or add additional context in comments.

3 Comments

thanks :) .It seems like more straight forward way ..But in which page will i give this code? I tried to give this in groupeditempage.js.. but its not working
I tried to give this code in many place.. but all time container only contain basic html(means with winjs controls declerations ) even after i assigned every values
According to msdn.microsoft.com/en-us/library/windows/apps/br212680.aspx you can pass a collection to pointerDown so maybe you can do WinJS.UI.Animation.pointerDown(document.querySelectorAll(".header")) if each of your headings has a class of header.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.