Link to home
Start Free TrialLog in
Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America

asked on

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
            });
Avatar of leakim971
leakim971
Flag of Guadeloupe image

$('div[id*="landmark"]').each(function ()
            {
                $(this).text( $(this).attr("id") );
            });
Avatar of Tom Knowlton

ASKER

Wow...I was close!
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
$('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"]')
all the div with a class landmark

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

no (id contains)
It would be cool if EE could embed jsfiddle.net into the jQuery zone...so we could have a handy little sandbox.
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.
>>>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
thx