Search code examples
htmlcssinline

input tag inside p tag using jquery


$Option = "<p>6 &lt; x &lt; 8</p>"  //For demo I have assigned directly, in reality the value will come from MySQL database.

I want to display this value something like:

expected result

But I am getting it like:

reallity result

I know the reason why it is like that because the input tag is out of paragraph tag.

<input type="radio" name="<?php echo $i; ?>" value="A"><?php echo $Option; ?>

What can I do so that the radio button is inside paragraph tag?


Solution

  • p elements are block elements by default. You can make them inline elements by setting the display property value to inline:

    $Option = '<p style="display:inline">6 &lt; x &lt; 8</p>';
    

    Update: If you are not able to change the value of the variable then you can try using external or internal CSS:

    input[type=radio] + p{
      display: inline;
    }