0

I have CSS code like this.

.dl-container > .dl-submenu.dl-animate-out-2 { <<< My target

    Some code that I want to insert.

}

And this my Jquery code.

$( ***My target*** ).css("top", "500px" );

How Jquery insert top:500px; at my target CSS when I click some element on my website.

2
  • You cannot replace your css file. You can only do this for the page with jquery on any element. Commented Jul 22, 2015 at 11:19
  • 1
    You can only update inline css with $(elementSelector).css("top", "500px"); and you can't edit style on css file. Commented Jul 22, 2015 at 11:21

2 Answers 2

1

An other solution instead of the $(".myelement").css("top", "500px" ); could be to add a class.

.dl-container > .dl-submenu.dl-animate-out-2 {
   /* Base CSS */
   top: auto;
}
.dl-container > .dl-submenu.dl-animate-out-2.newClass {
   /* Some new CSS */
   top: 500px;
}

then

$(".dl-container > .dl-submenu.dl-animate-out-2").addClass('newClass');
Sign up to request clarification or add additional context in comments.

Comments

0

This is a working example of manipulating the css of the element .stupid.

$(document).ready(function(){
    $(".stupid").click(function(){
        $(".stupid").css("color", "red" );
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="stupid">Some stupid text</div>

You have to use

$(".myelement").css("top", "500px" );

If it works, accept it.

3 Comments

Can I replace ".dl-container > .dl-submenu.dl-animate-out-2" on ".myelement"?
I think you do not understand how jQuery works. That's ok, we are here to help. First thing to do is to find the desired element in your html code and add it a class called, let's say ".stupid". Then you add the jquery code to the page. You can't modify a css directly.
Thank you.I will try it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.