0

I am having problem with following code. Its showing compliation error:- "Identifier Expected".

<script type="text/javascript" runat = "server">
function isOverElement(currentElement, targetId)
        {
            while (currentElement)
            {
                if (currentElement.id == targetId)
                    return currentElement;

                currentElement = currentElement.parentNode;
            }

            return null;
        }
</script>

The problem is in line:- function isOverElement(currentElement, targetId) Rest all is OK, I suppose.

please help. thnx

5
  • I assume that this is a js-function and not a C# function. So remove the runat=server. Commented Jan 4, 2012 at 13:01
  • What do you want to do with 'while (currentElement)' ? In my eyes it is a very bad coding style and often resonsible for lots of errors. Commented Jan 4, 2012 at 13:01
  • @ reporter, actually the lines inside the function is not cause for the error I'm getting. i'm pretty sure for it. Commented Jan 4, 2012 at 13:11
  • @tim:- absolutely correct. thanks Commented Jan 4, 2012 at 13:13
  • @ALL:- CHOOSING Darin Dimitrov's ANSWER AS BEST ANSWER... as it was fastest response. Just before JQONE. Thanks all Commented Jan 4, 2012 at 13:15

3 Answers 3

2

Remove the runat="server" attribute from your <script> tag. Javascript runs on the client, not on the server:

<script type="text/javascript">
    function isOverElement(currentElement, targetId) {
        while (currentElement) {
            if (currentElement.id == targetId)
                return currentElement;

            currentElement = currentElement.parentNode;
        }

        return null;
    }
</script>
Sign up to request clarification or add additional context in comments.

Comments

1

You don't need runat="server" for script tag. Try removing the runat and see if it working

Comments

1

Please remove the tag runat="server" since you have written a pure javascript function.

Change

<script type="text/javascript" runat = "server">  to  <script type="text/javascript">

1 Comment

thanks for the letting me know the reason for removing runat = "server" tag.

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.