开发者

Removing or altering CSS pseudo class in jQuery

开发者 https://www.devze.com 2023-03-14 23:09 出处:网络
A simple enough question, so briefly - is it possible to remove or alter in anyway a CSS pseudo class using jQuery? Or any other Javascript method for that matter

A simple enough question, so briefly - is it possible to remove or alter in anyway a CSS pseudo class using jQuery? Or any other Javascript method for that matter

Specifically I want to get rid of :foc开发者_如何学JAVAus on inputs. I can't alter the CSS file directly in any way.

thanks for any help

Buster


I can't alter the CSS file directly in any way.

Assuming you can only use JavaScript to do this, I can't think of anything better than:

$('head').append('<style>input:focus{background:#fff}</style>');

You will have to individually reset each property. font-weight:normal, color:#000 - whatever you need.

See: http://jsfiddle.net/jqpAu/


Without more specific detail it's hard to answer accurately, but if you want you can just override the :focus style:

// in the CSS file
input:focus {background-color: red;} 

// in your page
input:focus {background-color: inherit;} // overrides with the parent background

Demo


See this answer: Setting CSS pseudo-class rules from JavaScript

I think you are looking for a way to add CSS dynamically. Example: http://jsfiddle.net/zkMCY/

Code:

var style = '\
    <style type="text/css">\
        a:hover{ color: #a55; }\
    </style>';
$('body').append(style);


If you want to actually prevent the user from using your input, do that via your html:

<input disabled="disabled">


you can use $(selector).removeClass(className)

0

精彩评论

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