Forum Moderators: open
<script src="//code.jquery.com/jquery-2.2.4.min.js"></script>
<script>
document.onclick = function() {
if (toggle.el) {
alert('yes');
toggle.el.toggle();
}
}
$.fn.toggleClick = function(e) {
toggle.el = this;
toggle.el.toggle();
if (e.stopPropagation) e.stopPropagation();
e.cancelBubble = true;
return false;
}
</script>
// Usage
<div id="menu" style="position: absolute; display: none"></div>
<span onClick="$('#menu').toggleClick(event);
$('#menu').css({ 'right': 55, 'width': 152 });
$('#menu').ajax(link_to_script);">
Click
</span> // these didn't give an error, but didn't change anything, either
$(toggle.el).toggle();
toggle.el.style.display= 'none';
// this resulted in the same "is not a function" error
toggle.el.hide(); <script>
document.onclick = function() {
if (toggle.el)
$('#' + toggle.el).toggle();
}
$.fn.toggleClick = function(e) {
// moved this here from the document.onclick function for more testing
// alerts "menu"
alert( this.attr('id') );
// alerts "undefined"
alert( this.id );
////////
if (!toggle.el)
toggle.el = this.attr('id');
this.toggle();
if (e.stopPropagation) e.stopPropagation();
e.cancelBubble = true;
return toggle.el;
}
</script>
// Usage
<div id="menu" style="position: absolute; display: none"></div>
<span onClick="toggle.el = $('#menu').toggleClick(event);
$('#menu').css({ 'right': 55, 'width': 152 });
$('#menu').ajax(link_to_script);">
Click
</span>