0

This is absurd, I feel like in kindergarten. I've already tried any combination that I could think of, and I just gave up trying.

<script type="text/javascript">
function myFunction(){
 alert("test");
}
</script>


<a href="#" class="love" id="<?php echo $img_id; ?>" onclick="myFunction()">

This is a php file that is being "inserted" in a parent html, but I don't see why this would mess with javascript.

3
  • What is the problem, exactly? Commented Jun 10, 2012 at 18:55
  • 2
    It works for me, so you have probably created a reduced test case that has reduced the problem away entirely. Commented Jun 10, 2012 at 18:56
  • This is what bothers me. There is nothing else. The <a> tag is also closed. I just can't understand how this isn't working. Perhaps it is because this file is embedded in the parent html? It doesn't have its own head or body, it's just this script and some divs. Commented Jun 10, 2012 at 22:52

1 Answer 1

1

Close out your <a> tag:

<a href="#" class="love" id="<?php echo $img_id; ?>" onclick="myFunction()">TEST</a>

And your code works:

Working Example

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

3 Comments

It's highly unlikely that this is the problem. It's not at all clear what the OP's problem is, but if it were a missing end tag the question's title would probably be something like "can't click a link" or "link text is not visible". Anyway, not closing the tag would just make the rest of the page (or most of it) clickable.
@Juhana: I suspect the same too, hence provided the working example, rephrased my answer to avoid the confusion :)
It was closed, sorry, forgot to write it here.

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.