Solved

jQuery - Get all elements that end with a string

Posted on 2010-11-10
13
1,090 Views
Last Modified: 2012-05-10
I need to know how to get, via jQuery, all elements in a page ( specifically table tr's ) that end with the string "_trcontent" and hide these elements.

I have tried several site such as http://stackoverflow.com/questions/609382/jquery-selector-id-ends-with which have similar requirements, to no avail.
0
Comment
Question by:sydron
  • 6
  • 4
  • 3
13 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 250 total points
ID: 34108759
>Get all elements that end with a string.
<< all element >> ? You mean the id end

Use end selector : http://api.jquery.com/attribute-ends-with-selector/


jQuery('[id$="_trcontent"]').hide();

Open in new window

0
 

Author Comment

by:sydron
ID: 34108782
I tired that exact line of code and it did not work for me.
0
 
LVL 10

Expert Comment

by:hosneylk
ID: 34108829
how about this..
$('tr[id$="_trcontent"]').hide();

Open in new window

0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

Author Comment

by:sydron
ID: 34108841
That did not work either.

I call each element directly, say $("#ele_tr_content").hide(); in the same area where i place the suggested code it seems to work.

I can't figure out why this is occurring.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 34108850
So its tr_content with an underscore

_tr_content
_trcontent
0
 
LVL 10

Expert Comment

by:hosneylk
ID: 34108854
:)
0
 

Author Comment

by:sydron
ID: 34108856
My bad, it is _trcontent, my last post had it wrong.

 
0
 
LVL 10

Expert Comment

by:hosneylk
ID: 34108885
very strange... you're sure it's the exact code given above?

I have no idea if this will work but maybe you could give it a try.
$('#tableid tr[id$="_trcontent"]').hide();

Open in new window

0
 

Author Comment

by:sydron
ID: 34108891
Nope didn't work. Not sure whats going on .
0
 
LVL 10

Expert Comment

by:hosneylk
ID: 34108894
can you post the page source here?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 34108895
can we see the page on the internet?
0
 

Author Comment

by:sydron
ID: 34108898
it is an intranet app. ill try your suggestions on a new clean page and see it if works.  thanks.
0
 

Author Comment

by:sydron
ID: 34108969
I figured it out. It was the version of jQuery i was using. Thanks guys.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

856 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