开发者

What are all the different ways to rewrite this jquery

开发者 https://www.devze.com 2023-03-24 05:36 出处:网络
I have a command like this. .css(\'display\', \'block\') However, I think it could also be rewritten in different ways. For exampl开发者_开发技巧e,

I have a command like this.

.css('display', 'block') 

However, I think it could also be rewritten in different ways. For exampl开发者_开发技巧e,

.css('display : block') 

That may or may not be correct. I don't remember. Anyways, do you know different ways to rewrite the original command?


If you want to set a CSS property in jQuery, there are three methods:

.css( propertyName, value )
.css( propertyName, function(index, value) )
.css( map )

See the JQuery API documentation for more info


You mean .css({display:'block'}) and they are both exactly achieve the same thing. Except with my example you can set multiple css styles.


.css({display : 'block'}) 

Here is the alternative. This way you can apply more CSS properties to selected objects.


You can use the following

$("selector").show();
$("selector").css({display:"block"});


This is just reaching here, but:

<style>
    .i-like-the-taste-of-tofu { color: #29c411 }
</style>

....

<p class="this-is-gon-be-greenish">
    AMERICA IS A COUNTRY AND ALSO MOST OF THE WESTERN HEMISPHERE SO THERE
</p>

....

<script>
    $('#this-is-gon-be-greenish').addclass('i-like-the-taste-of-tofu');
</script>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号