2

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

3 Answers 3

3

Move definition of akkitooltip function outside document.ready function. It is not accessible from there.

Sign up to request clarification or add additional context in comments.

5 Comments

Just did it, now got this error Uncaught TypeError: Cannot read property 'replace' of undefined
Also you are passing the same values to applytooltip function. If there is no element on page with id as 'question_307' you will get an error.
Nope, there is a element with id question_307.
Is there a label inside it?
Yes there is a label inside.
0

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, i.e. $('' + 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

1 Comment

No, I am getting undefined, I just checked tooltipText on console, I got undefined.
0

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"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.