Solved

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

Posted on 2011-09-06
9
263 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:Tom Knowlton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:Tom 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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
LVL 5

Author Comment

by:Tom 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
 
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:Tom 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:Tom 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:Tom 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:Tom Knowlton
ID: 36492242
thx
0

Featured Post

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
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…

623 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