Reputation: 71
Or
I'm not familiar with scripts.
I've tried the code attached below, but it doesn't work.
How do I give a script like 01 or 02?
please help..!
※I used a translator because I couldn't speak English. That is why my words may not be natural. Please understand.
$(function(){
if ($('.A').css('position' == 'absolute')) {
$('.B').addClass('C');
}
else {
$('.B').removeClass('C');
}
});
Upvotes: 1
Views: 941
Reputation: 11
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<style>
.A {
position:absolute
}
.C {
color:red
}
</style>
<script>
$(document).ready(function(){
if ($('.A').css('position') == 'absolute') {
$('.B').addClass('C');
}
else {
$('.B').removeClass('C');
}
});
</script>
</head>
<body>
<p class="A">如果你点我</p>
<p class="B">继续点我!</p>
</body>
</html>
Upvotes: 1
Reputation: 6324
this should work as you expect
$(document).bind('DOMSubtreeModified', function () {
if ($('.A').css('position') == 'absolute') {
$('.B').addClass('C');
}
else {
$('.B').removeClass('C');
}
});
The above code will run whenever the DOM structure changes. The delay is caused by something on your side, after the dom changes it will call the above function.
You could try this, but it may not work
$(document).bind('change', function () {
if ($('.A').css('position') == 'absolute') {
$('.B').addClass('C');
}
else {
$('.B').removeClass('C');
}
});
Upvotes: 1