0

I have an action start element .oven_program_01, panel with class .oven_panel started after click at this element.

I have another element .back_button which closes this panel.

When I open the panel again I can't close it. The display does't change.

This is my script:

opening action:

$('.oven_program_01').live('click', function() {
    $('.back_button').addClass('oven_panel_close_button');
    $('.oven_panel').fadeIn(300);
});​

closing action:

$('.back_button').click(function() {
    if ($(this).hasClass("oven_panel_close_button")) {
        $('.oven_panel').fadeOut(300);
        $('.back_button').removeClass("oven_panel_close_button")
    }
    else {
        $(this).addClass("oven_panel_close_button")
    }
});​
Cœur
  • 37,241
  • 25
  • 195
  • 267
Lukas
  • 7,384
  • 20
  • 72
  • 127
  • Is the `.back_button` element dynamically added to the page? If so, you need to create a listener for that element; i.e. `$.on()`. In addition, the `$.live()` function has been depreciated. I suggest using `$.on()`. – JoeFletch Aug 20 '12 at 19:52
  • no, this element is stage, so i need to do smth like that ?$('.back_button').on('click', function() { – Lukas Aug 20 '12 at 19:57
  • This element is **stage**? Do you mean that this element is **static**? – JoeFletch Aug 20 '12 at 20:08
  • yeap, sorry 4 mistake :) – Lukas Aug 20 '12 at 20:10
  • The `$.on()` functions works 2 ways based on the parameters that you give it. `$('.back_button').on('click', function() { ...})` assumes that it is on the page all the time. But if the element is dynamic then you need to setup the `$.on()` function differently; `$("**body**").on("click", "**.back_button**", function() { ...})` where `$(ParentElement).on("click", ChildElement, function(){})` [jQuery.on()](http://api.jquery.com/on/) – JoeFletch Aug 20 '12 at 20:12
  • Yes. I would use the `$.on()` function. As @David said, make a Fiddle so that we can help further. – JoeFletch Aug 20 '12 at 20:14
  • so this is fiddle http://jsfiddle.net/J5ane/ and it's work, but it's one radical diferent .oven_program_01 are dinamicly creating from xml, and have numbers from 01-09, thats why i use live, i i guess that's why this script does't work :( – Lukas Aug 20 '12 at 20:40
  • this question migth help; http://stackoverflow.com/questions/11811980/jquery-how-to-convert-local-variable-to-a-global-variable – Barlas Apaydin Aug 20 '12 at 20:58

0 Answers0