Solved

select all divs with id containing A and set their inner text to the full id

Posted on 2011-09-06
9
255 Views
Last Modified: 2012-05-12
<div id='landmarkY' class='landmarkY'></div><!-- end of div landmarkY -->


What would be the jquery to set the innerText to the same thing as the id, like this:


<div id='landmarkY' class='landmarkY'>landmarkY</div><!-- end of div landmarkY -->

There are over 20 of these, so I need a generic way to refer to them, like "gather all divs with id containing "landmark" and set their inner text to the full id of said tag"

   $('div[id*="landmark"]').each(function ()
            {
                $(this).text(  ???????? not sure what
            });
0
Comment
Question by:knowlton
  • 6
  • 3
9 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 36492072
$('div[id*="landmark"]').each(function ()
            {
                $(this).text( $(this).attr("id") );
            });
0
 
LVL 5

Author Comment

by:knowlton
ID: 36492081
Wow...I was close!
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 36492092
test page : http://jsfiddle.net/ef75z/

using a unique class :

$('div.landmark').each(function ()
            {
                $(this).text( $(this).attr("id") );
            });

new test page : http://jsfiddle.net/ef75z/1/
0
 
LVL 5

Author Comment

by:knowlton
ID: 36492153
$('div.landmark').each(function ()
            {
                $(this).text( $(this).attr("id") );
            });


what is 'div.landmark' selecting?

is it the same same thing as this:

$('div[id*="landmark"]')
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 82

Expert Comment

by:leakim971
ID: 36492170
all the div with a class landmark

>is it the same same thing as this:
>$('div[id*="landmark"]')

no (id contains)
0
 
LVL 5

Author Comment

by:knowlton
ID: 36492188
It would be cool if EE could embed jsfiddle.net into the jQuery zone...so we could have a handy little sandbox.
0
 
LVL 5

Author Comment

by:knowlton
ID: 36492198
In the actual page, each div will have a unique class that it uses...so the first code was better for my purposes, I think.
0
 
LVL 5

Author Comment

by:knowlton
ID: 36492239
>>>no (id contains)


I get it now.  I didn't realize the class name was the same each time.

For my purposes, I am ignoring class and using id.


Now, is there a way to cut out the "landmark" part and just display the characters after?

instead of:

landmarkA
landmarkZ
landmarkWhatever
landmarkFoo
landmarkBar

the inner text for the div would just be:

A
Z
Whatever
Foo
Bar
0
 
LVL 5

Author Closing Comment

by:knowlton
ID: 36492242
thx
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn how to dynamically set the form action using jQuery.
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…

744 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

10 Experts available now in Live!

Get 1:1 Help Now