conditional check on span RRS feed

  • Question

  • User2131862557 posted

    I have below check

    if (typeof FUI !== 'undefined')



    and here is code which append text like

    div.append('<div span class="UNAME">' + FUN+ '</span>: ' + msg+ '</div>');

    I want if typeof FUI !== 'undefined') it should span /start text from left otherwise right ,any help

    Saturday, June 15, 2019 3:04 AM

All replies

  • User475983607 posted

    There are two issues.  The main issue is the markup is invalid which makes it difficult to understand the intent by looking at the code.  A <span> is an inline element and it is not possible for the contents of a span to be on the left or the right. 

    Can you share an example of the expected results?

    Saturday, June 15, 2019 12:07 PM
  • User2131862557 posted

    like if  below statement is true ,span in div is blue otherwise green

    say div is like

    <div Style ={color}><span>erum</span></div>

    if (typeof FUI !== 'undefined')



    Saturday, June 15, 2019 1:13 PM
  • User-2054057000 posted

    it should span /start text from left otherwise right ,any help

    I think you need jQuery Prepend method, as this method inserts the specific content as the first child of the selector.

    Sunday, June 16, 2019 3:20 AM
  • User839733648 posted

    Hi dua,

    According to your description, I've made a sample on my side.

    I've simulated a checkbox to make the condition of if statement.

    If the checkbox is checked, the color of the content will be blue.

    <!DOCTYPE html>
        <meta charset="utf-8" />
        <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
            $(function () {
                if ($('#checkbox1').prop('checked')) {
                    $("body").append($('<div style="color:blue;"><span>erum</span></div>'));
                else {
                    $("body").append($('<div style="color:green;"><span>erum</span></div>'));
        <input type="checkbox" id="checkbox1" checked="checked"/>  


    Best Regards,


    Monday, June 17, 2019 3:37 AM