How to add a class in Javascript/jQuery if an element has content in it?

后端 未结 4 1690
北荒
北荒 2021-01-25 08:56

I am working on a website in which I want to check whether element has any content in it.

Below is my html code. I have mentioned condition#1 where

4条回答
  •  悲&欢浪女
    2021-01-25 09:28

    i hope the following script will heplful.

    jQuery(function ($) {
        if ($(".featured-block__title").text().length != 0 && jQuery('.featured-block__tag').text().length != 0 ) {
            $(".img-fit img").addClass("opacity-pointseven");  // For condition#1
        } 
    });
    

提交回复
热议问题