Connect with us

News

How to: Show/Hide any div box with jQuery in WordPress

If you take a look at my current sidebar (right) and see the heading Google Search you’ll notice that when you click it the Google Search box show’s into view.

Let me show you how this is done.

First make sure that your WordPress site is calling jQuery, buy pluggin this code into our header.php file above the <?php wp_head(); ?> text:

<?php wp_enqueue_script('jquery'); ?>

Then anywhere above the </head >, plug this code in:

<script type="text/javascript">
jQuery(document).ready(function() {
 // hides the slickbox as soon as the DOM is ready
  jQuery('#toggle-search').hide();

 // toggles the slickbox on clicking the noted link
  jQuery('a#slick-slidetoggle').click(function() {
	jQuery('#toggle-search').slideToggle(400);
	return false;
  });
});
</script>

That’s simple, huh. Okay now lets write the Search code:

<h2><a href="#" id="slick-slidetoggle">Google Search</a></h2>
	<div id="toggle-search" style="padding:10px;">
    <form method="get" id="search" action="<?php bloginfo('home'); ?>/">
        <div>
            <input type="text" value="Enter Keyword" onclick="this.value='';" name="s" id="s" />
            <input type="text" name="search-button" id="search-button" value="<?php _e('Search') ?>" />
        </div>
    </form>
</div>

That’s it.

39 Comments

Random Search Terms

Title

Top Articles

powered by WassUp

Recent Posts: Fully Net Worth . com

Alejandro Rosario Net Worth: How Rich is the Tik Tok star?

Alejandro Rosario Net Worth: How Rich is the Tik Tok star?

Alejandro Rosario is an up and coming Internet superstar who is famous for his activities on an app called Tik Tok. Within a couple of months, Rosario has been able to gain a huge following on his Tik Tok account. As of 2019, Alejandro Rosario net worth is estimated to be $100,000. Alejandro was born […]

Cyril Hanouna Net Worth: How Rich is the French TV Star?

Cyril Hanouna Net Worth: How Rich is the French TV Star?

Cyril Valéry Hanouna is a French radio and television presenter, writer, and producer. Hanouna is a polarizing figure who is best known for being the host of the popular French TV show Touche Pas à Mon Poste! As of 2019, Cyril Hanouna net worth is estimated to be $5 million. Hanouna was born on 23 […]

Donna Marie Lombardi Net Worth- How Rich is Black Ink Crew Star?

Donna Marie Lombardi Net Worth- How Rich is Black Ink Crew Star?

Taylor Monet Pinkney, who is better known as, Donna Marie Lombardi, is a tattoo artist and an influencer. She is best known for playing an important role in the reality television series called Black Ink Crew which airs in VH1. As of 2019, Donna Marie Lombardi net worth is estimated to be $350,000. Donna was […]