Hi,
Wondering if anyone might be able to give me a hand with the following. I've got a couple of divs that I want to let editors change the Title attribute of. To do this I have created an editable area and a piece of jQuery that will grab the text from within this area and set the attr to it, which works fine.
I'm slightly stuck though on how to do this for multiple divs. Can I use 'this' somehow, or should I use a for loop?
Code explaination:
Take the h2 id=grabThis and append it to the title of the tab div
Thanks guysCode:<div class="tab" title="Original title"> <div class="editorTitle"> <h2>New title</h2> <p>Grab the text from the hidden H2 below and make this div's title equal to it.</p> <h2 id="grabThis">Profile</h2> </div> </div> <div class="tab"> <div class="editorTitle"> <h2>Another title</h2> <p>This is another fun paragraph of text</p> <h2 id="grabThis">Research</h2> </div> </div> <script> $(document).ready(function(){ var titleToAdd = $('#grabThis').text(); $('.tab').attr('title', titleToAdd); }); </script>



Reply With Quote




Bookmarks