Solved

JQuery selector question

Posted on 2013-02-05
5
286 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 82

Expert Comment

by:leakim971
Comment Utility
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
Comment Utility
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 82

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
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 82

Expert Comment

by:leakim971
Comment Utility
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
Comment Utility
Thanks :)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

743 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

12 Experts available now in Live!

Get 1:1 Help Now