I ran into a problem today.
Trying to add css attributes to a node through jquery to make it achieve the expected style performance.
But it doesn’t work.
But in another way.
Invalid spelling:
//这种写法不生效。 $dom.find("p.text-p").css("-webkit-line-clamp",3) ; //或$dom.find("p.text-p").css({"-webkit-line-clamp":3}) ;
Effective spelling:
//此处这个3,可以是个变量。 $dom.find("p.text-p").attr("style", "-webkit-line-clamp:" + 3);
Note that in this case, the css() method does not take effect for some special css properties, and general properties are still available.
The guess is to directly rewrite the dom structure, which is equivalent to writing inline style. which is
<p style="xxxxxx">yyyy</p>
such a form.
…
The post JavaScript, What’s wrong with jQuery’s css methods not working first appeared on Lenix Blog .
This article is reprinted from https://blog.p2hp.com/archives/9086
This site is for inclusion only, and the copyright belongs to the original author.