Solved

Bind rows from a table but not dynamically

Posted on 2014-02-04
1
280 Views
Last Modified: 2014-02-04
I need to bind to a rows click event on a table, but not dynamically as I want to hide to columns data, but completely stuck :-S

What I have is a simple table:-
<table id="example">
	<tr>
		<th>ID</th>
		<th>First</th>
		<th>Surname</th>
		<th>Number</th>
	</tr>
	<tr>
		<td>1</td>
		<td>Nettie</td>
		<td>Saltsman</td>
		<td>32452345</td>
	</tr>
	<tr>
		<td>2</td>
		<td>Wilson</td>
		<td>Paredes</td>
		<td>23452</td>
	</tr>
	<tr>
		<td>3</td>
		<td>Twyla</td>
		<td>Merryman</td>
		<td>1435345</td>
	</tr>
	<tr>
		<td>4</td>
		<td>Eustolia</td>
		<td>Fleischmann</td>
		<td>4567854678</td>
	</tr>
	<tr>
		<td>5</td>
		<td>Dustin</td>
		<td>Craig</td>
		<td>42564256</td>
	</tr>
</table>

Open in new window


Which I can easily add a bind on to get the first column data:-
    $("#example tr").click( function( e ) {
        var a = $(this).closest('tr').find('td:first').text();
        alert($(this).closest('tr').find('td:first').text());
    });

Open in new window


Now my problem come in, I want to hide the first column of data, but if I run my code now I get the first column of data, not was the first column of data. Looking at using dataTables jQuery plugin the html doesnt exitst for the first column anymore, so I need to bind the data instead of dynamically getting the data when the row is clicked.

Any ideas??????? Please
0
Comment
Question by:tonelm54
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 53

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 39832084
This seems to work http://jsbin.com/UwuMocU/1/edit?html,css,js,output
$("#example tr").click( function() {
      var $td= $(this).closest('tr').children('td'); 
    
      alert($td.eq(0).text());
    });

Open in new window

css
   
tr>th:first-child {display:none;}
tr>td:first-child {display:none;}

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question