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

<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
            });
LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?
 
leakim971PluritechnicianCommented:
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
 
leakim971PluritechnicianCommented:
$('div[id*="landmark"]').each(function ()
            {
                $(this).text( $(this).attr("id") );
            });
0
 
Tom KnowltonWeb developerAuthor Commented:
Wow...I was close!
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Tom KnowltonWeb developerAuthor Commented:
$('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
 
leakim971PluritechnicianCommented:
all the div with a class landmark

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

no (id contains)
0
 
Tom KnowltonWeb developerAuthor Commented:
It would be cool if EE could embed jsfiddle.net into the jQuery zone...so we could have a handy little sandbox.
0
 
Tom KnowltonWeb developerAuthor Commented:
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
 
Tom KnowltonWeb developerAuthor Commented:
>>>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
 
Tom KnowltonWeb developerAuthor Commented:
thx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.