What is Custom JavaScript ?
- Get link
- X
- Other Apps
Custom JavaScript ka matlab hai — aapka apna likha hua JavaScript code, jo kisi specific purpose ke liye website ya web page me use hota hai.
🔍 Simple Definition:
Custom JavaScript wo code hota hai jo developer apne project ke hisaab se likhta hai, taaki website me extra functionality, animation, validation, ya user interaction add kar sake.
💡 Example:
// Button click hone par message show karna
document.getElementById("btn").addEventListener("click", function() {
alert("Hello, Welcome to my website!");
});
Yah ek custom JavaScript code hai — ye button par click karte hi ek message dikhata hai.
🧠 Uses of Custom JavaScript:
-
Form Validation – jaise email ya password check karna
-
Animations – hover effects, slides, pop-ups
-
Dynamic Content – page reload kiye bina data change karna
-
Tracking or Analytics – user ke actions ko record karna
-
Custom Interactions – buttons, menus, ya modals ko control karna
Chahe aap website WordPress me bana rahe ho ya manually HTML me — aap custom JavaScript add karke uski functionality apne according badha sakte ho.
Chaho to mai batau kaise custom JavaScript WordPress ya HTML page me add kiya jata hai?
⚙️ Custom JavaScript kya karta hai?
Custom JavaScript basically aapke web page ko smart banata hai.
HTML aur CSS se sirf design aur structure banta hai,
lekin JavaScript se page interactive aur dynamic ho jata hai.
🔧 Custom JavaScript likhne ke 3 main tarike:
1. Inline JavaScript
Direct HTML tag ke andar likhte hain.
<button onclick="alert('Hello!')">Click Me</button>
2. Internal JavaScript
HTML file ke andar <script> tag me likhte hain.
<script>
function greet() {
alert("Welcome to my website!");
}
</script>
<button onclick="greet()">Say Hello</button>
3. External JavaScript
Alag .js file me likhte hain (best practice).
<!-- HTML file -->
<script src="script.js"></script>
// script.js file
console.log("This is custom JavaScript running!");
🎯 Custom JavaScript ke Common Uses:
| Use | Example |
|---|---|
| Form Validation | Check karo ki email sahi likha gaya hai ya nahi |
| Pop-up Alerts | User ko message show karna |
| Animations | Image slider ya fade effect banana |
| Dynamic Content | Page reload kiye bina content badalna (AJAX) |
| API Integration | External data fetch karna, jaise weather ya news |
| Custom Tracking | User clicks aur actions ko record karna (analytics) |
🧩 Custom JavaScript in WordPress:
Agar aap WordPress use kar rahe ho, to custom JavaScript add karne ke 3 ways hain:
-
Theme Customizer me (Appearance → Customize → Additional JS)
-
Through Plugin (jaise “Insert Headers and Footers”)
-
Manually via
functions.phpya child theme me script enqueue karke
Example (enqueue method):
function my_custom_script() {
wp_enqueue_script('custom-js', get_template_directory_uri() . '/js/custom.js', array(), '1.0', true);
}
add_action('wp_enqueue_scripts', 'my_custom_script');
🧠 Short Summary:
Custom JavaScript = Aapka apna code jo website me special function ya behavior add karta hai, jaise forms validate karna, buttons ko animate karna, ya dynamic content load karna.
- Get link
- X
- Other Apps
Comments
Post a Comment