I am trying to integrate a button function in jquery, I am a learner of jquery but i am not sure how scripting can be converted into jquery
Here is a code
<script type="text/javascript">
var _hmc = _hmc || [];
_hmc.push(['app', '<application ID>']);
_hmc.push(['title','Talk with us.']);
(function() {
var hm = document.createElement('script'); hm.type = 'text/javascript';
hm.async = true;
hm.src = 'https://hipmob.s3.amazonaws.com/hipmobchat.min.js';
var b = document.getElementsByTagName('script')[0]; b.parentNode.insertBefore(hm, b);
})();
</script>
I need to place it inside button click
jQuery('.live-chat').click(function()
{
});
Also if anyone would like to elaborate how things work eg what is || [] etc
The code you would need to do what you want is the following:
jQuery('.live-chat').click(function() {
var _hmc = _hmc || [];
_hmc.push(['app', '<application ID>']);
_hmc.push(['title','Talk with us.']);
var hm = document.createElement('script');
hm.type = 'text/javascript';
hm.async = true;
hm.src = 'https://hipmob.s3.amazonaws.com/hipmobchat.min.js';
var b = document.getElementsByTagName('script')[0];
b.parentNode.insertBefore(hm, b);
return false;
});
As for your questions:
||
means OR in javascript []
is shorthand for creating a new array, or an 'array literal' var _hmc = _hmc || [];
var _hmc = _hmc || [];
means _hmc
equals _hmc
OR a new array
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.