tags:

views:

155

answers:

3

I am new to JQuery but I've started by making a list creator essentially. I have an empty list and an input field and a link for the user to add elements to the list. When I add something, I would like it to be hidden at first and then show up dynamically using JQuery. Currently, it adds it to the list but it sets the display: block instead of display:list-item or nothing at all. Am I doing something wrong?

So here is some code

$('a#addstep').click(function() {
    if ( $('#step').val().length > 0 ) {
        $('<li />')
            .text($('#step').val())
            .hide()
            .appendTo('ol#instructions')
            .show('normal');
    }
});

Here is some HTML

<ol id="instructions"></ol>
<input type="text" id="step" size="60" />
<a href="#" id="addstep">Add</a>
A: 

try using

(".theclass").css("display", "inline {or your desired value}");

instead of show('normal')

simplyharsh
+2  A: 

I'm not exactly sure why your adding the extra calls to show/hide. When you add an item it will show it. Please explain further as to why you need to do the show/hide.

If you absolutely have to.

$('a#addstep').click(function() {    
    if ( $('#step').val().length > 0 ) {        
     $('<li />')            
     .text($('#step').val())            
     .hide()            
     .appendTo('ol#instructions')            
     .show('normal', function() {
      $(this).css('display', 'list-item')
     });    
    }
});
bendewey
I don't absolutely have to but the point of using JQuery is partially to make things look more visually appealing. The fades help.
Joe Philllips
That sort of does the trick. I'll probably see if I can get it to display as a list-item before calling show() so it's in the proper order. Thanks!
Joe Philllips
Maybe I was misunderstanding the use of show(). It seems that fadeIn() does the same thing without undesirable results.
Joe Philllips
A: 

Try this (untested):

$('a#addstep').click(function() {
    if ( $('#step').val().length > 0 ) {
        $('<li />')
            .css('display', 'list-item')   // ADDED
            .text($('#step').val())
            .hide()
            .appendTo('ol#instructions')
            .show('normal');
    }
});
strager