locked
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>
    <html>
    <head>
        <meta charset="utf-8" />
        <title></title>
        <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
        <script>
            $(function () {
                //$("div").find("span").eq(0).remove().end().eq(1).addClass("red");
                //$("div").find("span").eq(0).remove().end().end().find("span").eq(1).addClass("red");
                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>'));
                }
            })
        </script>
        <style>
            .red{
                color:red;
            }
        </style>
    </head>
    <body>
        <input type="checkbox" id="checkbox1" checked="checked"/>  
    </body>
    </html>

    result:

    Best Regards,

    Jenifer

    Monday, June 17, 2019 3:37 AM