?
Solved

Bind rows from a table but not dynamically

Posted on 2014-02-04
1
Medium Priority
?
283 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 2000 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
Suggested Courses
Course of the Month14 days, 1 hour left to enroll

801 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