开发者

how do you get the specific style altered with a CSS class?

开发者 https://www.devze.com 2023-04-09 02:46 出处:网络
Quick 开发者_高级运维one, not sure if its possible. How can I get the specific style altered with a CSS class using jQuery/JS.

Quick 开发者_高级运维one, not sure if its possible.

How can I get the specific style altered with a CSS class using jQuery/JS. Example:

html looks like:

<tab>

    <a class="anchor">a</a>

</tab>

CSS looks like:

a{border:1px}

.anchor{color:green}

So if i do something like :

$('.anchor').myReturnStyle() and it returns color or an array if there more styles in .anchor

$('.anchor').MyReturnStyleValue('color') returns 'green'

BUT

$('.anchor').returnStyleValue('border') returns false as this is not changed by .anchor Class


You can use jQuery's css(..) method to achieve this. Please note that:

Shorthand CSS properties (e.g. margin, background, border) are not supported.

Here is an example:

<div>
    <a class="anchor">a</a>
</div>

<style type="text/css">
a { background-color: #000; }
.anchor{ color: green; }
</style>

<script type="text/javascript">
$(document).ready(function () {
    alert($($('.anchor').get(0).nodeName).css('background-color'));
});
</script>

See the jsFiddle demo

0

精彩评论

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