Overwrite The Show Method In Jquery
am editing a web app (not my code) , and has alot of modals show up when some message or notification come so i want to add a sound for that modal the problem that this modal is i
Solution 1:
I agree with the comments that it's probably not the best idea and it seems a bit hacky, but it can be done.
So what the JQuery .show()
method does is just change an element's CSS to display: block;
right? So you can overwrite the .show
method, but tell it to keep doing that and then also add some additional functionality:
jQuery.fn.show = function() {
this.css('display', 'block');
setTimeout(() =>alert('My very own added functionality'), 0);
returnthis;
};
$('a').click(function() {
$('div').show()
})
div {margin-top: 20px; background-color: blue; height: 60px; width: 60px; display: none;}
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><ahref="#">Click to show div</a><div></div>
Working JSFiddle here:
Post a Comment for "Overwrite The Show Method In Jquery"