Reputation: 286
I have a link in to the title attribute in a div like this -
<div class="tooltip" title="<a onclick='ersal();'>send</a>"><img src="<?php echo "admin/".$item['img'] ?>" width="70" height="70" /></div>
and I have a function in jquery that name is ersal()
<script type="text/javascript">
$(document).ready(function() {
function ersal(){
alert("Clicked!");
};
});
</script>
but when I click to link send my function doesn't work why?
Upvotes: 0
Views: 107
Reputation: 412
For handling hover event, you should use this code:
HTML CODE:
<div class="tooltip" title="Click here">
<img src="<?php echo "admin/".$item['img'] ?>" width="70" height="70" />
</div>
JS CODE:
$(document).ready(function() {
var c = $(document);
c.on("mouseenter",".tooltip",function(){ alert("Clicked!"); });
});
Upvotes: 2
Reputation: 109
You can't add an url in the title attribute.
Try like that, for example :
<a id="my-link" class="tooltip" href="#" title="Link to Image">
<img src="<?php echo 'admin/'.$item['img'] ?>" width="70" height="70" />
</a>
And your jQuery
should be :
$('#my-link').click(function(){
alert('clicked');
});
Or :
$('#my-link').click(function(){
ersal();
});
function ersal(){
alert('clicked');
}
Upvotes: 1
Reputation: 2265
Your HTML code should be like this-
<div class="tooltip" title="Click here" onclick='ersal()'>
<img src="<?php echo "admin/".$item['img'] ?>" width="70" height="70" />
</div>
For handling click event, you should use onclick
property and the value for it can be javascript code or any javascript function call. The syntax can be given like this -
<element onclick="Somejavascriptcode">
Upvotes: 3