JavaScript

How to expand Autocomplete in jQuery by clicking on a button
How to expand Autocomplete in jQuery by clicking on a button

The jQuery framework includes a component called Autocomplete, which displays suggestions (input options) directly below the text input field as it’s being typed. Similar to how autocomplete works in search engines like Google or Yandex.

In one of the projects, there was a task to display the full list of available options when clicking a button.

Let’s take a closer look at how to implement this. The first thing we need to do is include all the necessary scripts and libraries:

<link rel="stylesheet" href="../bower_components/jquery-ui/themes/base/all.css">
<script src="../bower_components/jquery/dist/jquery.min.js"></script>
<script src="../bower_components/jquery-ui/jquery-ui.min.js"></script>

read more...

How to Add Custom JavaScript Code to WordPress
How to Add Custom JavaScript Code to WordPress

While working on one of the WP projects, I needed to add some JS code. Normally, for such tasks, I use separate script files. However, in this case, the code was minimal, so I decided to place it directly into the HTML "body" of the document.
To do this, use the following PHP code:

add_action('wp_enqueue_scripts', function(){
	if(!wp_script_is( 'jquery', 'done' ))
	{
		wp_enqueue_script( 'jquery' );
	}
	wp_add_inline_script( 'jquery-migrate', 'alert("Hello")' );
});

Here's what we are doing:

read more...