How to include HTML page with jQuery

If you are familiar with PHP, there you can quickly embed another PHP or HTML file within your page using include and require statements.

This saves time when you need to add the same line of code in several files.

If you are not using the server-side script on your webpage then you can use the iframe or Client-side scripting language.

There are two ways in jQuery for including a file in another HTML file –

  • AJAX request
  • .load() method

How to include HTML page with jQuery

Read more

How to Use before() and after() method in jQuery

In CSS before and after pseudo-elements use to add style to the targeted selector elements.

There are two methods with a similar name in jQuery.

They adjust the position or add the element before and after instead of changing CSS.

In this tutorial, with examples, I show how you can use before() and after() methods on your webpage.

How to Use before() and after() method in jQuery

Read more

Custom Right Click Context menu with jQuery

Sometimes it is required to show a custom context menu instead of the browser default one when right-clicking on the webpage or on a specific element.

By doing that it is possible to show a context menu according to the element and disable the default menu where necessary.

It is customizable according to the website design.

For implementing this I am using jQuery in this tutorial.

When right-clicking on the element then disable the browser default context menu and display the custom options.

Custom Right Click Context menu with jQuery

Read more

Dynamically add and remove element with jQuery

In this post, I show how you can add and remove new elements within your web page with jQuery.

There are two approaches to doing this –

  • Pre-made all elements
  • Dynamically create a new element

The first case is easy but you have to create all of the elements at once and hide them which is not required currently.

When you have to add an element you need to display the element one by one and for removing hide them.

Here the problem is – there are multiple unused elements are available which occupy space within your code and make it messy even if you don’t have needed some of the elements.

The second solution is better than the first where you can create and remove an element dynamically when you have to require.

In this tutorial, I am using the second solution.

Dynamically add and remove element with jQuery

Read more