Jquery :contains showing alert for all span

前端 未结 4 1342
旧时难觅i
旧时难觅i 2021-01-14 16:10

I have a span Text goes her like this

$(\'#contentarea\').bind(\'click\',function(e){
             


        
4条回答
  •  孤独总比滥情好
    2021-01-14 16:37

    $(e.target).find(":contains(font-weight: bold;)")
    

    It always returns a jQuery collection of objects - including 0 length collection. This is not a javascript list and you always get true in boolean.

    var target = $(e.target);
    if(target.is('span')){
         if(target.css('font-weight') == 'bold'){
             alert('bold');
         }
    }
    

提交回复
热议问题