I am sure that as a front-end developer, you will have faced many issues with jQuery functions. Sometimes, I used to wonder if there was a way we could change the default behavior of jQuery functions. Many times, in our project, we believe if we can change the default behavior of jQuery function, we can achieve our objective and complete our project easily with a good standard of code.
Well, it's possible.
Let's see how to do that with an example.
Well, it's possible.
Let's see how to do that with an example.
Example
In this example, I will be overriding the default functionality of 2 of the most used functions in jQuery, i.e., Hide and Show.
In this example, I will be overriding the default functionality of 2 of the most used functions in jQuery, i.e., Hide and Show.
As the name suggests, the Hide function by default hides the elements it's applied upon and Show is the function that makes the hidden element visible.
Let's try to modify the default behavior.
In our current implementation, the Show function will show the element in blue color and the Hide function will show the element in red color with stricken text in it.
Following is the HTML code for the same.
- <input id="show" type="button" value="Show" />
- <input id="hide" type="button" value="Hide" /><br />
- <div class="elems">first line</div>
- <div class="elems">second line</div>
- <div class="elems">third line</div>
The output will be.

Let's modify the JS file to override the jQuery Show and Hide functions.


Sagar Pandurang KapPosted Jan 30, 2018, 1:24 AM
Great piece of stuff..