Hi i'm having trouble selecting items that are next to each oterh and
would love some help
The first issue is a dynamic table with a "remove row" link in the
last column
For each row in the table i want to add an onclick event to the
"remove row" link, that refers to some information contained in the
columns of that particular row (for e.g. the unique database column
name to remove)
<thead>
<tr>
<th>No</th>
<th>User</th>
<th>Role</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<tr>
<td> RandomNo3 </td>
<td> ImAUniqueDBEntry (thisUser) </td>
<td> ImaDbValue (thisRole) </td>
<td><a href="#" class="remove">remove</a></td>
</tr>
</tbody>
this is what i used:
$.each( $('tr:gt(0)'),function(i,val){
//role=this row, all children, cell 3
var thisRole = $(this).children().eq(2).html()
//role=this row, all children, cell 2
var thisUser =$(this).children().eq(1).html()
$(this).append("<td><a href=\"#\" class=\"remove\">remove</a></
td>");
//selects the link element with class remove in the last cell of
selected row
$
(this).children().eq(3).children().filter('.remove').click(function(){
//add click event to the remove link
editDbRow('MyRemoveRowFunction', ''+thisRole+'' ,''+thisUser+'');
return false;
});
});
}
That works but is there an easier way? i'm trying to understand jquery
syntax..
On a similar note, i have the same problem again.
I have a html select input in a table row.
One of the select options dynamically adds a text box directly after
the html select.
If i change this option though, i want to remove the text box. How do
i select this text box?
e.g.
<select class="select_other" name="test">
<option selected="selected" value="" label="Please Select
Action....">Please Select Action....</option>
<option value="0" label="Other (specify)">Other (specify)</option>
<option value="1" label="Hazard removed or controlled">Hazard removed
or controlled</option>
</select>
$(.select_other).change(function(){
var newName=$(this).attr('name')
newName = newName.replace('[action]','[customAction]');
if ($(this).val() == 0){
var newInput='<br/><input class="newText" type="text"
name="'+newName+'">';
$(this).after(newInput);
}
else{
//remove The text box?
// console.log($(this).parent.siblings().html());
//What selector would i use
here? thanks!
}
});
Thanks for your help in advance!