0

Update:

Got it. I need to change the div structure. The nameP div wraps nameE so there needs to be a separate div for Ptext.

<div class="element">
<div class="nameP">
    <div class=PP>Ptext</div>
    <div class="nameE">Etext</div>
</div>
</div>

I struggled with the title here. Using jquery Isotope. Code will hopefully explain:

<div id="container">

    <div class="element">
        <div class="nameP">Ptext<BR>
        <div class="nameE">Etext</div>
    </div>
    </div>
several more <div class="element"> repeats
</div>

There is a button outside "container" which when clicked I would like to reverse the contents of all ...class="nameP" with ...class="nameE". There are other divs being exchanged but I figure if I get it for one I can do it for all.

I hope this is clear and I hope you have some suggesions. thx

Arfa
  • 105
  • 9

1 Answers1

0

attach the following function to the click event of your button :

function handler() {
    $('.element').each(function(){
        var temp = $(this).find('.nameP').text();
        $(this).find('.nameP').text($(this).find('.nameE').text());
        $(this).find('.nameE').text(temp);
    });
}
Neil S
  • 2,304
  • 21
  • 28
  • Instanto! reply! First run has a success. I will need a while to test against all the bits I missed out to be sure there is not conflict - and have to leave now for about an hour. So far... GREAT. thanks. I'll be back with an update. – Arfa Sep 10 '13 at 22:23
  • Reminds of a toggle routine for table row backgrounds. But... nameP gets nameE but something doesn't quite make it for nameE. I tried .text('qweqwe'); on that last line but even that didn't insert. The other thing is that if the button is clicked again - zero. Somehow nameP is dissapearing. I follow your logic, it 'should' work - but... I will look further at other possible conflicts. – Arfa Sep 11 '13 at 00:28
  • yea, unless you can provide a fiddle to show where it's failing, I don't know that I can help diagnose further. – Neil S Sep 11 '13 at 00:40
  • see update above. The thing I have to do now is block the toggle - I didn't mention there were 2 bottons; P & E. – Arfa Sep 11 '13 at 01:13