how can i access my td class via jquery here is HTML code
<td class="selectable" id="shoes-<?= $color->id ?>" ></td>
<td><a href="?shoes=<?php echo $color->id; ?>" title="Select"
<?php if($shoes==$order->shoes){ ?> class="selected"<?php } ?>>
Here is jQuery Code
$('td.selectable a').click(function() {
var $parent = $(this).parent();
var data = $parent.attr('id').split('-');
var type = data[0];
var typeId = data[1];
if i alert (type); i receive nothing could you help
now i got it solved but second part still problem I am trying to switch my class it should show up while clicking on a link here is the html code
<td class="selectable" id="person-<?= $person->id ?>">
<a href="?person=<?php echo $person->id; ?>" title="Selecteren"
if($person==$order->person){ ?> class="selected"<?php } ?>><?php echo $person->name;?></a></td>
it works with span class and div class but with a class=selected does not work
$('#personAmount td.selectable a').click(function() {
var $parent = $(this).parent()
var data = $parent.attr('id').split('-');
var type = data[0];
var typeId = data[1];
switch(type){
case 'person'开发者_运维问答:
$(this).prepend('<a class="selected"></a>');
break;
case 'color':
$(this).prepend('<div class="checked"></div>');
break;
default:
$parent.prepend('<span class="checked"></span>');
}
$('td a').click(function(e) {
var id = $(this).closest('tr').find('.selectable').attr('id');
var d = id.split('-');
var item_type = d[0];
var type_id = d[1];
alert(type_id);
alert(item_type);
});
working demo
In your code, the <td>
that includes the <a>
doesn't have id
and class
attributes. The click
event won't be bound to that <a>
$(this).parent().prev();
You've got a hierarchy like this:
<td class="selectable"></td>
<td>
<a>
Using your current HTML:
Live Demo
$('td.selectable + td a').click(function() {
var $parent = $(this).parent().prev();
var data = $parent.attr('id').split('-');
var type = data[0];
var typeId = data[1];
alert(type);
});
精彩评论