Tom Knowlton
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'>landmark Y</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"]').e ach(functi on ()
{
$(this).text( ???????? not sure what
});
What would be the jquery to set the innerText to the same thing as the id, like this:
<div id='landmarkY' class='landmarkY'>landmark
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"]').e
{
$(this).text( ???????? not sure what
});
ASKER
Wow...I was close!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
$('div.landmark').each(fun ction ()
{
$(this).text( $(this).attr("id") );
});
what is 'div.landmark' selecting?
is it the same same thing as this:
$('div[id*="landmark"]')
{
$(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)
>is it the same same thing as this:
>$('div[id*="landmark"]')
no (id contains)
ASKER
It would be cool if EE could embed jsfiddle.net into the jQuery zone...so we could have a handy little sandbox.
ASKER
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.
ASKER
>>>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
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
ASKER
thx
{
$(this).text( $(this).attr("id") );
});