**i am trying to put an event handler based on CSS condition and it doesn't work,any help please ** here is my HTML code :
<!Doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jquery test</title>
<style>
.x{color:red;}
</style>
</head>
<body>
<input id="trigger" type="button" value="test"/>
<p class="x" >some text</p>
<p>another text</p>
<script type="text/javascript" src="js/jQuery.js"></script>
<script type="text/javascript" src="js/match.js"></script>
</body>
</html>
and here is the jquery code :
$('#trigger').click(function(){
if($('p.x').css("color") === "red")
{
var text= $('p').text();
alert(text);
}
});
Working JSFiddle
As adeneo said, 'red' gets converted to RGB.
Javascript:
$('#trigger').click(function(){
if($('p.x').css("color") == 'rgb(255, 0, 0)'){
var text= $('p.x').text();
alert(text);
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.