Say I have an unordered list, like so:
<ul> <li>One</li> <li>Two</li> <li>Three</li> <li>Four</li> <li>Five</li> </ul>
How would I, using JQuery, hide the last 2 list items and have a 'show more' link there, so when clicked upon, the last 2 list items would appear?
<ul> <li>One</li> <li>Two</li> <li>Three</li> <li style="display:none;">Four</li> <li style="display:none;">Five</li> <li>Show More</li> </ul>
The hide() method hides the selected elements. Tip: This is similar to the CSS property display:none. Note: Hidden elements will not be displayed at all (no longer affects the layout of the page). Tip: To show hidden elements, look at the show() method.
Syntax: $(selector).hide(speed,callback); $(selector).show(speed,callback);
jQuery toggle() MethodThe toggle() method toggles between hide() and show() for the selected elements. This method checks the selected elements for visibility. show() is run if an element is hidden. hide() is run if an element is visible - This creates a toggle effect.
ready(function(){ jQuery('body').
Try the following code example:
$('ul li:gt(3)').hide(); $('.show_button').click(function() { $('ul li:gt(3)').show(); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With