开发者

how can i access td class via jQuery?

开发者 https://www.devze.com 2023-03-03 10:22 出处:网络
how can i access my td class via jquery here is HTML code <td class=\"selectable\" id=\"shoes-<?= $color->id ?>\" ></td>

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);
});
0

精彩评论

暂无评论...
验证码 换一张
取 消