2

I want know the what is the effect of id and function when both are same. Example:

<tr> <td><img id='deleteAuthor' onclick='javascript: deleteAuthor(this)' src='images/close.png' /></td></tr>";
        function deleteAuthor(element){
            alert(element);
        }
    output:TypeError: deleteAuthor is not a function
    [Break On This Error]   


    <tr> <td><img id='deleteAuthorbt' onclick='javascript: deleteAuthor(this)' src='images/close.png' /></td></tr>";
       function deleteAuthor(element){
        alert(element);
      }
    output:Object HTMLImageElement

Please Why it behave so?

3

1 Answer 1

2

U have to use different names for id and function. Same names for both will cause ambiguity

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

1 Comment

It isn't ambiguous, the scoping and overriding rules are consistent. A better solution is to avoid doing everything in the global scope.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.