How To Learn
How To Learn

Reputation: 301

applying right margin dynamically using jquery

#dock > li ul
        {
            position: absolute;
            bottom: 0px;
            left: -180px;
            z-index: 1;
            width: 180px;
            display: none;
            background-color: #F1F1F1;
            border: solid 1px #969696;
            padding: 0px;
            margin: 0px;
            list-style: none;
        }

This is my css class and I want to apply a right margin dynamically using jquery. Any thoughts appreciated. I tried this:

$('#dock').children('li').children('ul').css({ 'margin-right': rmargin });

but it seems to be not working.

Upvotes: 4

Views: 489

Answers (3)

Oscprofessionals
Oscprofessionals

Reputation: 2174

$('#dock > li ul').css({ 'margin-right': rmargin });

Upvotes: 1

Rohan Kumar
Rohan Kumar

Reputation: 40639

Try

$('#dock').find('ul').css({ 'margin-right': rmargin });

ul must be a child or a grand child of #dock other wise it may not works

In that case you can use

$('#dock > li ul').css({ 'margin-right': rmargin });

Docs http://api.jquery.com/find

Upvotes: 4

Dipesh Parmar
Dipesh Parmar

Reputation: 27364

Use it as below,

$('#dock > li ul').css({ 'margin-right': rmargin });

$('#dock > li ul') this will select all UL inside of LI tag which is direct child of #dock DOM.

Upvotes: 0

Related Questions