0

I want to add a class for some elements in jquery, and then i want to add a new class for the elements with the new class, but it does not working.

my code:

jQuery(document).ready(function () {
    jQuery('.nagyul').click(function () {
        jQuery(this).removeClass('nagyul');
});

    jQuery('.ajtoo').click(function () {
        jQuery(this).removeClass('ajtoo');
});
    jQuery('.indulas').click(function () {
        jQuery('.indulas').not(this).addClass('masodik');
}); 
    jQuery('.masodik').click(function () {
        jQuery('.masodik').not(this).addClass('harmadik');
}); 
    jQuery('.harmadik').click(function () {
        jQuery('.harmadik').not(this).addClass('negyedik');
});
    jQuery('.negyedik').click(function () {
        jQuery('.negyedik').not(this).addClass('otodik');
});
    jQuery('.otodik').click(function () {
        jQuery('.otodik').not(this).addClass('hatodik');
});
    jQuery('.hatodik').click(function () {
        jQuery('.hatodik').not(this).addClass('hetedik');
});
    jQuery('.hetedik').click(function () {
        jQuery('.butorok').removeClass('butorok');
}); }); 

jQuery represents $, but the wordpress doesn't understand it just this way. The website is: http://www.honlapkell.hu/room/fooldal/

Every object has on the picture a class called "indulas", and my plan to remove the class "butorok" from the background picture if the user clicked on every object. So it would be colorful too.

  • Do not wrap every single line with `jQuery(document).ready(function () {` Yikes.... – epascarello Jan 29 '15 at 02:38
  • I don't even know where to begin... I guess by asking: Why are you opening and closing the `jQuery(document).ready()` so many times? This code is a mess... – RhapX Jan 29 '15 at 02:38
  • Your code isn't very readable. If you combine all the event handler setup calls into a single jQuery(document).ready(..) call, and indent your code nicely, it would be easier to read/provide an answer. – Fiddles Jan 29 '15 at 02:41
  • You need to use event delegation – Arun P Johny Jan 29 '15 at 03:21
  • Also see - http://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements – Arun P Johny Jan 29 '15 at 03:28

0 Answers0