Jquery: si la clase existe

I want something that finds instantly on the page a class called prop Y póngalo en hidden soon as there is one.

IMPORTANT: soon as a new element is added I want that element with prop class changed. Like a while loop

if( class='prop' == found ){

     set class to ('hidden');

}

And yes this function is inserted after the element caller. but it seems like it takes some time till the element is generated so I need a check on the class to remove it as fast as possible. I cant use a delay in this case have tried that with bad results.

preguntado el 08 de noviembre de 11 a las 12:11

Does this mean you are adding the elements with class prop ¿dinamicamente? -

3 Respuestas

You need hasClass function

if($('selector').hasClass('prop'))
    {
        $(this).removeClass("prop");
        $(this).addClass("hidden");
    }

Esto podría ayudar a

respondido 08 nov., 11:17

$('.prop').hide()

Documentación: http://api.jquery.com/class-selector/

Or if you want to add a class 'hidden' instead:

$('.prop').addClass('hidden')

respondido 08 nov., 11:17

is that working like a while loop? or does it just toggle? I need some kind of a IF(){ --- } - nxtlvlhax

Instead of using a while loop why not trigger this call when ever an element is added. Seems more efficient - Gaurav Shah

see @Avanq answer... A generic solution though I would suggest it to call manually rather than on "DomNodeInserted" .. - Gaurav Shah

It does no properly work cuz the calculation of the element function will take longer on every diffrent computer. so I need something like a loop or just a if check in that function. yes something like that. thanks for reply - nxtlvlhax

javascript tiene some events that keep track of changes in DOM, you can use those.

$('body').bind('DOMNodeInserted', function(){
  $('.prop', this).hide();
});

respondido 08 nov., 11:17

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.