Solved

Bind rows from a table but not dynamically

Posted on 2014-02-04
1
273 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
1 Comment
 
LVL 52

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now