Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Bind rows from a table but not dynamically

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

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

DOM Attributes and Properties treatment with jQuery 1.6 by Ivo Stoykov jQuery (http://jquery.com/) 1.6 introduces .prop() (http://api.jquery.com/prop/) and .removeProp() (http://api.jquery.com/removeProp/) methods which allow modifying or removi…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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)
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…
Suggested Courses

636 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