Solved

JQuery selector question

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

Accepted Solution

by:
leakim971 earned 500 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 82

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Link not working 6 41
Can't get cursor to change 3 15
Html using "Or" in condition 3 24
Prevent certain words from being typed in a form 6 24
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

685 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