I have a few button created in PHP, when I try calling a jQuery function based on the button class name. The function on click doesn't seem to work.
PHP
$style = " margin: 0px; background-color: transparent; border: none;";
$functionname= "selectedpic(this.id)";
$styleimage = "HEIGHT= 120 WIDTH= 120 BORDER= 0";
$eventimage1= "zoomin(this)";
$eventimage2= "zoomout(this)";
$btnclass="btnclass";
echo "<button name='" . $btn. "'
margin ='".$style."'
onClick='".$functionname."'
class='".$btnclass."'
>";
jquery
$(".btnclass").click(function () {
var clickedButtonName = this.name;
alert ("hi");
});
Your code looks ok make sure the javascript is inside <script></script>
tags
and try wrapping your jQuery code in $(document).ready();
ie.
$(function(){
$(".btnclass").click(function () {
var clickedButtonName = this.name;
alert ("hi");
});
});