On onclick I am getting Uncaught ReferenceError: akkiTooltip is not defined
.
Check the code that I am using:
$(document).ready(function () {
function akkiTooltip() {
function applyTooltip(element, word) {
var tooltipText = $('' + element + ' label').data('tooltip');
var newContent = $('' + element + ' label').html().replace(word, '<span data-tooltip="' + tooltipText + '">' + word + '</span>');
$('' + element + ' label').removeAttr('data-tooltip');
return $('' + element + ' label').html(newContent);
}
applyTooltip('#question_307', 'Some text');
}
});
This is from another js file where I am applying onclick:
$(button)
.text(this.answers[a].title)
.attr('type', 'button')
.attr('class', 'btn')
.attr('onclick', 'quiz._makeSelection(\'answer_' + this.answers[a].id + '\', ' + go + ', ' + this.answers[a].skipToSection + '); akkiTooltip();');
After moving akkiTooltip
function outside $(document).ready
function, I am getting this error
Uncaught TypeError: Cannot read property 'replace' of undefined
Move definition of akkitooltip
function outside document.ready
function. It is not accessible from there.
Cannot read property 'replace' of undefined
See where you are using .replace
$('' + element + ' label').html().replace(word, '...');
So, $('' + element + ' label').html()
is not what you expect, ie $('' + element + ' label')
found no elements so .html()
did not return a String
Check an element described by the selector #question_307 label
exists
When I tried reproducing this error I actually got null
instead of undefined
so it might be a different piece of your code
maybe you should check if you set right:
1.In html and jsp webpage:
<script src=""></script>
2.In xhtml webpage:
<script src="" />
3.and if your js code(function code) is in the same webpage with the html, you can just use:
<script> {your js code} </script>
the default script type is "test/javascript"
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.