Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

95
Views
I want to add a style or class using a script
  1. I want to give the script to add "Class=C" to "Class=B" when "Class=A" has "position: absolute" style.

Or

  1. I want to give the script so that when "Class=A" has the style "position: absolute", it adds the style "bottom: 0px" to "Class=B".

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');
    }
});

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

this should work as you expect

$(document).bind('DOMSubtreeModified', function () {
    if ($('.A').css('position') == 'absolute') {
        $('.B').addClass('C');
    }
    else {
        $('.B').removeClass('C');
    }
});

Edit 1

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.

Edit 2

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');
    }
});
about 4 years ago · Juan Pablo Isaza Report

0

<!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>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!