0

this is my simple code:

var qibla = $(".qd .wpb_wrapper").text();
        $('#qdir img').css('transform', 'rotate(' +qibla +'deg)');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<div class="wpb_wrapper">
    <div class="wpb_raw_code wpb_content_element wpb_raw_html qd">
    <div class="wpb_wrapper">
    218.4
    </div>
    </div>
    <div class="w-image us_custom_9c0cfcca align_center" id="qdir"><div class="w-image-h"><img width="300" height="300" src="https://s20.picofile.com/d/8447362450/a60ba95e-4386-462e-8f26-10d69847adbf/download_1.svg" class="attachment-medium size-medium" alt="" loading="lazy"></div></div></div>

I want to get text value from "qd" element, that is 218.4

ad then set it into "#qdir" as css rotation attribute. but not work.

1 Answer 1

1

This is because the qibla variable has additional space and enter character at the beginning and the end. Just use trim() function to remove them.

More information: https://www.w3schools.com/jsref/jsref_trim_string.asp

var qibla = $(".qd .wpb_wrapper").text().trim();
$('#qdir img').css('transform', 'rotate(' +qibla +'deg)');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<div class="wpb_wrapper">
    <div class="wpb_raw_code wpb_content_element wpb_raw_html qd">
    <div class="wpb_wrapper">
    218.4
    </div>
    </div>
    <div class="w-image us_custom_9c0cfcca align_center" id="qdir"><div class="w-image-h"><img width="300" height="300" src="https://s20.picofile.com/d/8447362450/a60ba95e-4386-462e-8f26-10d69847adbf/download_1.svg" class="attachment-medium size-medium" alt="" loading="lazy"></div></div></div>

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.