return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>javascript - how can i access td class via jQuery? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how can i access td class via jQuery? - Stack Overflow

programmeradmin2浏览0评论

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>');

        }

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>');

        }
Share Improve this question edited May 5, 2011 at 21:22 mary asked May 5, 2011 at 19:25 marymary 1491 gold badge5 silver badges10 bronze badges 2
  • I don't understand what are you trying to do with inserting those elements in the <a>. In the first case of the switch, you are inserting an <a> inside the current '<a>'. – morgar Commented May 5, 2011 at 21:21
  • i am trying to add an image which is behind the class=selected infront of mine td which has a also hope it is a bit clear with div and span i can add this image in my list only with class selected it does not show up. i just removed the a now i have it like this $(this).prepend('<class="selected">'); still no success – mary Commented May 5, 2011 at 21:31
Add a ment  | 

4 Answers 4

Reset to default 4
$('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)

  1. 暂无评论