Cos
Cos

Reputation: 1709

javascript function on click doesn't work

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.

Upvotes: 0

Views: 273

Answers (1)

Sarfraz
Sarfraz

Reputation: 382881

Close out your <a> tag:

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

And your code works:

Working Example

Upvotes: 1

Related Questions