Hai Truong IT
Hai Truong IT

Reputation: 4187

Can't change css when using click in jquery

I have a small demo:

<div class="box_content_height">
    <strong>Height: </strong>
    <input type="text" name="height" id="height" value="300" />px
    <input type="submit" class="submit_advance" value="submit" />    
</div>

And javascript

$('.submit_advance').click(function() {
        var height_css = $('#height').val();
        $('ul.nav-scroll').css('max-height', height_css+'px');
});

When I type input = 500 is result css no change 500 How to result is

.ul.nav-scroll {
    max-height: valueofinput+px
}

Upvotes: 1

Views: 115

Answers (3)

Zen Pak
Zen Pak

Reputation: 578

is this a typo? Your css definition has a "." in front of ul:

.ul.nav-scroll {     max-height: valueofinput+px }

your javascript selector does not correspond with the above:

$('ul.nav-scroll').css('max-height', height_css+'px'); 

Your css should be:

ul.nav-scroll {     max-height: valueofinput+px }

Upvotes: 0

Jacob
Jacob

Reputation: 78920

Your submit may be causing the page to reload due to the form being submitted, undoing your changes. If you don't want this to happen, add a return false to the end of your handler.

Upvotes: 1

busypeoples
busypeoples

Reputation: 737

change this :

$('ul.nav-scroll').css('height', height_css+'px');

Upvotes: 1

Related Questions