Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

jQuery - Get all elements that end with a string

Posted on 2010-11-10
13
Medium Priority
?
1,118 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 83

Accepted Solution

by:
leakim971 earned 1000 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 83

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 83

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…
Suggested Courses

916 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