If loop with css in JQuery

2
$('#label-user').click(function(){
    if ($('#label-user').style.display != 'none') {
        $('#label-user').css('display', 'none');
    }       
});

    
asked by anonymous 03.10.2016 / 21:01

1 answer

2

The .style.display syntax is for native JavaScript, as you are using jQuery it would be .css('display') != 'none' .

You can also do everything in-house within the callback:

$('#label-user').click(function(){
    if (this.style.display != 'none') {
        this.style.display = 'none';
    }       
});

Or using jQuery with .hide() :

$('#label-user').click(function(){
    $(this).hide();     
});

In fact it seems to me that it would suffice

$('#label-user').click(function(){
     this.style.display = 'none';     
});

Because a hidden element can not click anyway ...

    
03.10.2016 / 21:03