🔥 Black Friday: Up to 50% Off All Plans
Days
Hrs
Min
Sec

Need Help?

Here are some good places you cant start.

Whats New?

Get updated about all the good stuff!

wordpress-black-friday-deals-2025
Unlimited Elements for Elementor – Version 2.0
Unlimited Elements for Elementor – Version 2.0

How to create a custom Elementor Widget with Javascript

You can add JavaScript to your own widgets in the widget creator, for example to make an element react to a click. The code runs on every page where you use the widget.

Step 1

In your WordPress dashboard, go to Unlimited Elements > Widgets and open your widget in the widget creator. If you don’t have a widget yet, see How to create your first Elementor widget.

Step 2

Open the HTML tab and give the main element of the widget the id {{uc_id}}. Every copy of the widget on a page gets its own id, so your code works only on its own widget. In this example, button_text is a Text Field attribute of the widget:

				
					<div id="{{uc_id}}" class="my-widget">
	<button class="my-widget__button">{{button_text}}</button>
</div>
				
			

Step 3

Open the Javascript tab and write your code. You can use attributes and variables here too, for example {{uc_id}} to find the widget:

				
					jQuery(document).ready(function(){

	var objWidget = jQuery("#{{uc_id}}");

	objWidget.find(".my-widget__button").on("click", function(){
		objWidget.toggleClass("is-active");
	});

});
				
			
Javascript tab of the widget creator

Step 4

If your code uses jQuery or another library, open the js/css Includes tab. Under Libraries, select the library, for example jQuery. To add your own file, use Js Includes or Css Includes.

Libraries and JS and CSS includes in the widget creator

Click Update to save the widget.

Video Overview

Hurray!

You got FREE access to the worlds leading widgets for Elementor page builder!

Download is just a click away

Get instant access to tons of Elementor goodies, completely FREE!