Avatar of Jon Imms
Jon Imms
Flag for United States of America asked on

change HTML dom tree with Jquery

I'm trying to alter the default layout for my testimonials section on my WordPress website.

At the moment, it outputs the HTML as

<div class="avia-testimonial_inner">
<div class="avia-testimonial-image"></div>
<div class="avia-testimonial-content"></div>
<div class="avia-testimonial-meta"></div>
</div>

Open in new window


What i want is

<div class="avia-testimonial_inner">
<div class="avia-testimonial-image"></div>
<div class="avia-testimonial-meta"></div>
<div class="avia-testimonial-content"></div>
</div>

Open in new window


I have 2 functions,  The first one works and has the image first, but i cannot get the meta class above the content. What am i doing wrong here?

WEBSITE

//------------------------------
// php -  Testimonial image on top
//------------------------------

function move_image_up_custom_script(){
?>
<script>
jQuery(function() {
    jQuery$('.avia-testimonial-image').prependTo($('.avia-testimonial_inner'));
     });
</script>
<?php
}
add_action('wp_footer', 'move_image_up_custom_script');

    

function add_custom_script(){
?>
<script>
jQuery(function() {
    jQuery$('.avia-testimonial-content').appendTo($('.avia-testimonial_inner'));
     });
</script>
<?php
}
add_action('wp_footer', 'add_custom_script');

Open in new window

HTMLPHPjQuery

Avatar of undefined
Last Comment
Julian Hansen

8/22/2022 - Mon
leakim971

What about : http://api.jquery.com/before/
http://api.jquery.com/insertbefore/
or "after"...

//------------------------------
// php -  Testimonial image on top
//------------------------------

function move_image_up_custom_script(){
?>
<script>
jQuery(function() {
    jQuery$('.avia-testimonial-image').prependTo($('.avia-testimonial_inner'));
     });
</script>
<?php
}
add_action('wp_footer', 'move_image_up_custom_script');

    

function add_custom_script(){
?>
<script>
jQuery(function() {
    jQuery$('.avia-testimonial-content').before($('.avia-testimonial-meta'));
     });
</script>
<?php
}
add_action('wp_footer', 'add_custom_script');

Open in new window

ASKER CERTIFIED SOLUTION
Julian Hansen

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy