jQuery check if element have specific attribute

后端 未结 6 759
忘了有多久
忘了有多久 2021-01-06 03:07

I am trying to see if an element have a specific CSS attribute. I am thinking at something like this:

if ( !$(this).attr(\'font-style\', \'italic\')) {
alert         


        
6条回答
  •  一向
    一向 (楼主)
    2021-01-06 04:05

    How about this

     if ($(this).css('font-style', 'italic')) {
        alert ("yes")
        }
        else {
        alert ("nop")
        }
    

    But I'd rather use console.log instead of alert if I were you, use firebug its less annoying and more fun :D

     
    

    I don't see why this shouldn't work..

提交回复
热议问题