?
Solved

JQuery selector question

Posted on 2013-02-05
5
Medium Priority
?
293 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
[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
  • 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 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 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

Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

777 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