I have little experience in using the $.fn.extend jQuery function; The code below is not working and it would seem that it would work as I've copy pasted it from this StackOverflow answer (jQuery Toggle Text?) The below code is as simple as I can get where the second function is not working... JSFiddle (http://jsfiddle.net/qxcwo51n/16/) however in my working example on a private site the 'toggle_active_iot' works but the extended function doesn't
$.fn.extend({
toggleText: function(a, b) {
return this.text(this.text() == b ? a : b);
}
});
function toggle_active_iot(link) {
$('.iot-items').toggleClass('active');
$('.iot-products').toggleClass('active');
}
.iot-items,
.iot-products {
display: none;
}
.active {
display: block !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class='col-md-12'>
<h3 style='background-color:#151515;color:white;padding:10px;margin:0px;'>
<i class="far fa-hdd"></i> Internet of Things
<button onClick="$(this).toggleText('Items','Products');toggle_active_iot(this);">Items</button>
</h3>
</div>
<div class='iot-items active'>
Test Items
</div>
<div class='iot-products'>
Test Products
</div>
`: http://jsfiddle.net/qxcwo51n/28/. This is also why the snippet I added in to your question works. I would suggest you get rid of the `onclick` attribute and use proper unobtrusive event handlers, suich as jQuery's `on()`
– Rory McCrossan Sep 07 '18 at 14:18