Solved

jQuery - Get all elements that end with a string

Posted on 2010-11-10
13
1,085 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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. …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

758 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

21 Experts available now in Live!

Get 1:1 Help Now