Solved

Bind rows from a table but not dynamically

Posted on 2014-02-04
1
270 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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Get value before .onChange() 5 25
jQuery Animate Left Right 2 43
jQuery CSS Scroll Issue 3 30
jqplot Pie Chart - javascript 2 7
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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…

744 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

11 Experts available now in Live!

Get 1:1 Help Now