Rich-text Reply

Using Jquery unexpectedly rearranges elements

kmalone 01-02-19

Using Jquery unexpectedly rearranges elements

[ Edited ]

Hello,

Having an issue where when I use a simple Jquery event listener to manipulate DOM elements, the parent element is being rearranged to its original position. Not sure why this might be happening. If someone would be able to shed some light on the situation I would be grateful!

 

MY Jquery here:

 

$(document).ready(function(){  
  $('input:checkbox').change( 
    function(){
        if ($(this).is(':checked')) {
          $('.monthly-val').css('display', 'none');
        }
        else
        {
          $('.monthly-val').css('display', 'block');
        }
    });
});

 

This is what it looks like before I fire the Jquery event:
INITIAL.png

 

And this is after:

AFTER.png

 

All the parent elements rearrange after I attempt to target the $15/$25/$50/mo ('.monthly-val') text inside them. Cant figure it out Smiley Frustrated

 

Level 2

RyanC 01-03-19
 

Re: Using Jquery unexpectedly rearranges elements

I would first assign an "id" to the element you want to manipulate and then you would no longer rely on the parent/child level changing.
Ryan
------------------------------------------------
The best solution is the simplest.

https://www.linkedin.com/in/ryan-camilleri
Experimentation Hero