Link to home
Start Free TrialLog in
Avatar of Ron Malmstead
Ron MalmsteadFlag for United States of America

asked on

$(allmessages).each(function (i, obj)...not iterating through all <span> elements. Only the first one.

I'm having a problem with iterating through a class in Jquery...
The $(allmessages).each(function (i, obj) ... is not executing for every <span> with the class of '.encryptedtext'

It hits the first message, decrypts it perfectly, but then doesn't execute the code on the next span.
I verified that the class is present on every span where the encrypted messages exist using 'inspect' feature in Chrome.

            function (data) {


                var ServerResponse = String(data);
                ServerResponse = unescape(ServerResponse);
                //alert(ServerResponse);
               $(".divinner").html(ServerResponse);
               // $(".divinner").append(ServerResponse);
                var allmessages = $('.encryptedtext');
                $(allmessages).each(function (i, obj) {
                    //test
                    var encryptedtext = $(obj).html();
                    encryptedtext = encryptedtext.replace(' ', '+');
                    //alert('message recieved encrypted: ' + encryptedtext);
                    //alert('message unescaped: ' + unescape(encryptedtext));
                    //alert('channel id and key: ' + channelid + key);

                    var decryptmsg = decrypt(encryptedtext, channelid + key);
                    alert('message decrypted:' + decryptmsg.toString(CryptoJS.enc.Utf8));
                    var plaintxt = decryptmsg.toString(CryptoJS.enc.Utf8);
                    var tempobj = obj;
                    $(obj).html(plaintxt);
                    $(obj).removeClass();
                    $("#panel1").animate({ scrollTop: $('#panel1')[0].scrollHeight }, 2400);
                });

Open in new window

Avatar of Ron Malmstead
Ron Malmstead
Flag of United States of America image

ASKER

This is the contents returned by the call to the server service (RoomHandler.ashx).

... These are the html contents I'm trying to iterate through.  If there is another way I would love to see some ideas...

<div id="div131914457058551193"  style="padding: 3px; margin: 3px; border: thin solid #99CCFF; overflow: hidden;border-radius: 5px; -moz-border-radius: 5px">
   
    <table style="text-align: left;">
        <tr style="vertical-align: top;">
            <td class="style1" rowspan="2">
    <div id="PofileDiv">
    
    <img src="profiles/img/DefaultProfilePic.png" /></div>
            </td>
            <td class="style2">
    <div id="divNull">
    
        
    
    <span title="1/8/2019 1:28:25 PM" style="margin-right:15px;"><font color="Blue" size="2">testuser</font></span><span><br /></span><span class="encryptedtext">9486d37d2fd029ca30836717d540c1944787194478b897d44a7ccceac56c13efsewPlsSH1TsxY M9s8yqDOID6Hrc3bObcITpE408g8c=</span></div>
            </td>
        </tr>
       
    </table>
    </div>
    
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="2CAA77DE" />
<div id="div131914457164785885"  style="padding: 3px; margin: 3px; border: thin solid #99CCFF; overflow: hidden;border-radius: 5px; -moz-border-radius: 5px">
   
    <table style="text-align: left;">
        <tr style="vertical-align: top;">
            <td class="style1" rowspan="2">
    <div id="PofileDiv">
    
    <img src="profiles/img/DefaultProfilePic.png" /></div>
            </td>
            <td class="style2">
    <div id="divNull">
    
        
    
    <span title="1/8/2019 1:28:36 PM" style="margin-right:15px;"><font color="Blue" size="2">testuser</font></span><span><br /></span><span class="encryptedtext">5aedb9abcb7186a9cdc3fab84c02f0957cc9a1fa7c51dc990492f4082b3eaaa7L3NcNC4i5z5WYQC7i4WB iqFhebpRd88jbO8Ijvs1JU=</span></div>
            </td>
        </tr>
       
    </table>
    </div>
    
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="2CAA77DE" />
<div id="div131914457738920268"  style="padding: 3px; margin: 3px; border: thin solid #99CCFF; overflow: hidden;border-radius: 5px; -moz-border-radius: 5px">
   
    <table style="text-align: left;">
        <tr style="vertical-align: top;">
            <td class="style1" rowspan="2">
    <div id="PofileDiv">
    
    <img src="profiles/img/DefaultProfilePic.png" /></div>
            </td>
            <td class="style2">
    <div id="divNull">
    
        
    
    <span title="1/8/2019 1:29:33 PM" style="margin-right:15px;"><font color="Blue" size="2">testuser</font></span><span><br /></span><span class="encryptedtext">ebc9b788961310ada4bc13b2c3f627e2a588c585409e6a4d37887da5be246392fHn5hgUeGouQh5Myil50/22wxA/o85t4EacEWCvmpog=</span></div>
            </td>
        </tr>
       
    </table>
    </div>
    
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="2CAA77DE" />
<div id="div131914457835745209"  style="padding: 3px; margin: 3px; border: thin solid #99CCFF; overflow: hidden;border-radius: 5px; -moz-border-radius: 5px">
   
    <table style="text-align: left;">
        <tr style="vertical-align: top;">
            <td class="style1" rowspan="2">
    <div id="PofileDiv">
    
    <img src="profiles/img/DefaultProfilePic.png" /></div>
            </td>
            <td class="style2">
    <div id="divNull">
    
        
    
    <span title="1/8/2019 1:29:43 PM" style="margin-right:15px;"><font color="Blue" size="2">testuser</font></span><span><br /></span><span class="encryptedtext">8d6eca09bce9b11f76af7a8ef35fb2727454b7e34764b3809f417958012d63b2ECeviigerZHZFXhPZKJNqQ==</span></div>
            </td>
        </tr>
       
    </table>
    </div>
    
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="2CAA77DE" />

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ron Malmstead
Ron Malmstead
Flag of United States of America 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
find how much you have to be sure placing an alert just after : var allmessages = $('.encryptedtext');

var allmessages = $('.encryptedtext');
alert(allmessages.length);

Open in new window