Results 1 to 3 of 3

Thread: On click ticket ID open message-content tr

  1. #1
    Join Date
    Nov 2011
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default On click ticket ID open message-content tr

    hi all

    I am trying to open message-content tr on click ticket ID

    but its not opening message-content tr

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <style type="text/css">
    #imaptable{border:1px solid #CCCCCC; border-collapse:collapse}
    #imaptable td{padding:3px}
    #imaptable th{background-color:#eee; padding:3px;}
    .message-content{display:none}
    </style>
    </head>
    <body>
    <table width="100%" border="1" cellspacing="0" cellpadding="0" id="imaptable">
    <tr>
    <td><a href="" class="ticket">Ticket ID</a></td>
    <td class="date">Mon, 7 May 2016</td>
    <td class="from">John</td>
    <td class="subject">Subject : inquiry df</td> 
    </tr>
    <tr>
    <td class="message-content" colspan="5">first ticket message comes here</td>
    </tr>
    <tr>
    <td><a href="" class="ticket">Ticket ID</a></td>
    <td class="date">Mon, 12 May 2016</td>
    <td class="from">Sam Cook</td>
    <td class="subject">Subject : getting latest phone</td> 
    </tr>
    <tr>
    <td class="message-content" colspan="5">second ticket message comes here</td>
    </tr>
    </table>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script type="text/javascript">
    var msgopen = $('.message-content');
    $('.ticket').click(function(e) {
       msgopen.hide();
       $(this).closest("tr").next(".message-content").show();
    });
    </script>
    </body>
    </html>
    vineet

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    The class (message-content) is on the td element, but that's not within the next() category (must be a same level child of the parent of the element being searched from) of the tr you get with closest("tr"). Long story short, move the message-content class to the tr elements. Also the click function on an a tag that has an href (even an empty one) must be at least default prevented, otherwise the page will reload before or immediately after the action is carried out (changes/additions highlighted, 3 places):

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <style type="text/css">
    #imaptable{border:1px solid #CCCCCC; border-collapse:collapse}
    #imaptable td{padding:3px}
    #imaptable th{background-color:#eee; padding:3px;}
    .message-content{display:none}
    </style>
    </head>
    <body>
    <table width="100%" border="1" cellspacing="0" cellpadding="0" id="imaptable">
    <tr>
    <td><a href="" class="ticket">Ticket ID</a></td>
    <td class="date">Mon, 7 May 2016</td>
    <td class="from">John</td>
    <td class="subject">Subject : inquiry df</td> 
    </tr>
    <tr class="message-content">
    <td colspan="5">first ticket message comes here</td>
    </tr>
    <tr>
    <td><a href="" class="ticket">Ticket ID</a></td>
    <td class="date">Mon, 12 May 2016</td>
    <td class="from">Sam Cook</td>
    <td class="subject">Subject : getting latest phone</td> 
    </tr>
    <tr class="message-content">
    <td colspan="5">second ticket message comes here</td>
    </tr>
    </table>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script type="text/javascript">
    var msgopen = $('.message-content');
    $('.ticket').click(function(e) {
       msgopen.hide();
       $(this).closest("tr").next(".message-content").show();
       e.preventDefault();
    });
    </script>
    </body>
    </html>
    Last edited by jscheuer1; 08-22-2016 at 01:11 AM. Reason: English Usage
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Nov 2011
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks jscheuer1

    Its working perfect now

    vineet

Similar Threads

  1. Disable right click image menu only with message
    By gusgus in forum Looking for such a script or service
    Replies: 1
    Last Post: 08-08-2011, 08:27 AM
  2. Replies: 1
    Last Post: 03-11-2010, 07:13 PM
  3. Replies: 22
    Last Post: 10-07-2008, 04:16 AM
  4. Replies: 10
    Last Post: 06-17-2008, 06:14 PM
  5. How to disable right-click on images w/o alert message?
    By nikiobicata in forum JavaScript
    Replies: 7
    Last Post: 03-27-2008, 03:18 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •