?
Solved

JQuery selector question

Posted on 2013-02-05
5
Medium Priority
?
296 Views
Last Modified: 2013-02-05
I have the following HTML Table
<table class="display" style="width: 1000px;" id="failoverServers">
	<thead>
		<tr>
			<th class="row_selector_head"> <input type='checkbox' class='select_all_chkbx'/></th>
			<th><div>{% trans "IP ADDRESS" %}</div></th>
			<th><div>{% trans "VIRTUAL IP ADDRESS" %}</div></th>
			<th><div>{% trans "USERNAME" %}</div></th>
			<th><div></div></th>
		</tr>
	</thead>

	<tbody>
	{% for i in list %}
		<tr rel="{{ i.id }}">
			<td class="row_selector"><input type='checkbox'/></td>
			<td rel="ip">{{ i.ipAddress }}</td>
			<td rel="virtualIP">{{ i.virtualIpAddress }}</td>
			<td rel="username">{{ i.username }}</td>
			
		</tr>
	{% endfor %}

	</tbody>
</table>

Open in new window


If I do the following:
           
      var list = "";
	            $('#failoverServers td.row_selector.selected').each(function() {
		        var row = $(this).closest('tr');
		        var id = row.attr('rel');
		        list += id + " ";			
		    });

Open in new window


Then I have a list of the numbers in the very first checkbox column.

I want to get a list of the following from the table:
            
<td rel="ip">{{ i.ipAddress }}</td>

Open in new window


What jquery selector do I use for this??

Thanks
0
Comment
Question by:Wanting2LearnMan
  • 3
  • 2
5 Comments
 
LVL 83

Expert Comment

by:leakim971
ID: 38856601
var list = "";
                  $('#failoverServers td.row_selector.selected').each(function() {
                    var row = $(this).closest('tr');
                    var id = row.find("td[rel='ip']").text();
                    list += id + " ";                  
                });
0
 

Author Comment

by:Wanting2LearnMan
ID: 38856641
Hi leakim971, your answer works, just one more thing:
What I want to do is to just get all the ip items from the table whether they are selected or now (Just get all them, they dont have to be selected)

How do I do this?
0
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 38856655
So remove << .selected >>
var list = "";
                  $('#failoverServers td.row_selector').each(function() {
                    var row = $(this).closest('tr');
                    var id = row.find("td[rel='ip']").text();
                    list += id + " ";                  
                });

Open in new window

0
 
LVL 83

Expert Comment

by:leakim971
ID: 38856670
or just :
var list = [];
$("td[rel='ip']", '#failoverServers').each(function() {  list.push( $(this).text() ); })
list.join(" ");

Open in new window

0
 

Author Closing Comment

by:Wanting2LearnMan
ID: 38856803
Thanks :)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
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

850 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