I'm sure your sick of me by now... but here's another question.
I can't seem to make jQuery listen for the click on a class of items. In the code below, I have a table with a button on each row with the class "btn". I just want jQuery to fire when I click the button to log in the console.
I have a "regular" html sample that works just fine:
- Code: Select all
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript">
$( document ).ready(function() {
console.log( 'document loaded' );
$('.btn').click( function() {
console.log('HI');
});
});
</script>
</head>
<body>
<table id='thisTable' width='100%' cellpadding='5' cellspacing='0'>
<tr id='1'><td>One</td><td><button type='button' class='btn'>X</button></td></tr>
<tr id='2'><td>Two</a></td><td><button type='button' class='btn'>X</button></td></tr>
<tr id='3'><td>Three</a></td><td><button type='button' class='btn'>X</button></td></tr>
</table>
</body>
</html>
Next, I set up the same thing in Servoy using a HTML area in a form variable, with a button:
- Code: Select all
function onAction(event) {
var aHTML = ["<html><head><script type='text/javascript'>" + getScript() + "</script></head><body>"]
aHTML.push("<table id='thisTable' width='100%' cellpadding='5' cellspacing='0'>");
aHTML.push("<tr id='1'><td>One</td><td><button type='button' class='btn'>X</button></td></tr>");
aHTML.push("<tr id='2'><td>Two</a></td><td><button type='button' class='btn'>X</button></td></tr>");
aHTML.push("<tr id='3'><td>Three</a></td><td><button type='button' class='btn'>X</button></td></tr>");
aHTML.push("</table></body></html>");
fv_sHTML = aHTML.join("");
}
function getScript() {
script = "$( document ).ready( function() {" +
"console.log( 'document loaded' );" +
"$('.btn').click( function() {" +
"console.log('HI');" +
"});" +
"});";
return script;
}
When I click the button - it pushes it into the head of the document just fine, and the console reads "document loaded". (ALL GOOD)
However, when I click the button - the console doesn't update with "HI" - like it does in the static HTML.
This is Servoy 7.4.9 on Windows 10 with Java 1.8.0_121
Any ideas on what I'm doing wrong?
![Shocked :shock:](./images/smilies/icon_eek.gif)