Can't select grid item via jQuery
This is the next question for ASP.NET How to pass container value as javascript argument
Darin Dimitrov kindly provided his answer using jQuery , <br / "> But for some reason I was unable to select the grid row I wanted.
Here is the jQuery used for row selection.
$(function() {
$('#_TrustGrid input[name^=trustDocIDTextBox]').each(function(index) {
$(this).click(function() {
alert('Hello world = ' + index);
setGridInEditMode(index);
});
});
});
Here is the actual HTML markup.
<input
id="_TrustGrid_ctl16_ctl05_ctl00_trustDocIDTextBox"
type="text" value="198327493"
name="_TrustGrid$ctl16$ctl05$ctl00$trustDocIDTextBox"/>
I just started using jQuery tonight and am going through the official jQuery Selectors but with no success.
Did I miss something?
source to share
I don't know why choosing via #_TrustGrid
didn't work. I was able to work around the problem by specifying :input
as shown below.
$(function() {
//$('#_TrustGrid input[id$=trustDocIDTextBox]').each(function(index) {
$(':input[id$=trustDocIDTextBox]').each(function(index) {
$(this).click(function() {
alert('Hello world = ' + index);
setGridInEditMode(index);
});
});
});
source to share
At first glance, I think you just want "$" instead of "^" and you should target the ID and not the NAME in your selector?
$(function() {
$('#_TrustGrid input[id$=trustDocIDTextBox]').each(function(index) {
$(this).click(function() {
alert('Hello world = ' + index);
setGridInEditMode(index);
});
});
});
source to share