JavaScript jQuery- Add text to same line of each radio input jquery same text,jquery find same text

So I am trying to make a dynamic quiz and am struggling with adding text to my radio inputs. I use a for loop to make several radio inputs. I would like the text to be on the same line as each radio choice, but I cannot accomplish this.

When I use append() it creates a new line then adds the text.

for (j = 0; j < 5; j++) {
            $('#target').append('<input type="radio" name="radioName"/>')
            $('#target').append('<p>My text here</p>');

When I use the label for html attribute, it adds the text at the end of all the radios.

for (j = 0; j < 5; j++) {
            $('#target').append('<input type="radio" name="radioName"/>').after("<label for='radio'>text here</label>");

Here is my jsFiddle showing the example: http://jsfiddle.net/tCkuF/2/

Ideally I would like to add a variable that represents an object as the text so it changes automatically as the quiz is taken.

Answer:1

It is recommended to use a list element in such cases

<div id="container">
    <div id="question"></div>
    <div id="target">
        <ul id="options">

        </ul>
    </div>
</div>

Also give styles

#options{
    list-style:none;
    list-style-type:none;
}

Then add li element. Give proper id for using for attribute

var $li = $("<li>").appendTo("#options");
$li.append('<input id="option' + (j+1) + '" type="radio" name="question' + i + '" value="' + allQuestions[i].correctAnswer + '"/>');
$li.append("<label for='option" + (j+1) + "'>test: label for adds all to the end    </label>");

demo : http://jsfiddle.net/tCkuF/6/

Answer:2

Your desired output can be achieved by simply adding a div wrapper around the radio & 'label'. Check this out:

$(function () {
var i = 0;
var allQuestions = [{
    question: "What is 4x6?",
    choices: [46, 15, 25, 24],
    correctAnswer: 3
}, {
    question: "What is 21x 21?",
    choices: [441, 2121, 388],
    correctAnswer: 0
}, {
    question: "Which number is prime?",
    choices: [1, 5, 10, 39],
    correctAnswer: 1
}, {
    question: "What is 65/5",
    choices: [3, 31, 12, 13, 21],
    correctAnswer: 3
}];

function populateQuestion() {
    $("#question").text(allQuestions[i].question); //add question
    var $target = $('#target'),
        j = 0;
    //add radio and answer choices
    for (j; j < allQuestions.length; j++) {

        (function (idx) {

            var html = '<div class="answerRow"><input class="answerRadio" type="radio" name="question' + idx + '" value="' + allQuestions[idx].correctAnswer + '"/><label class="answerRadioLabel"  for="question' + idx + '">test: label for adds all to the end    </label>';
            $target.append(html);
        })(j);
    }
}

populateQuestion();


}); //onload jQuery close
Answer:3

I have input type=file for upload file. When I choose 2-3 files, I have list of file. How can I delete only one object which I choose? <input type="file" data-ng-click="initFiles2()" data-rule-...

I have input type=file for upload file. When I choose 2-3 files, I have list of file. How can I delete only one object which I choose? <input type="file" data-ng-click="initFiles2()" data-rule-...

  1. delete object from array javascript
  2. delete object from array
  3. delete object from list python
  4. delete object from s3 bucket
  5. delete object from photo
  6. delete object from object javascript
  7. delete object from memory python
  8. delete object from vector c++
  9. delete object from photo in photoshop
  10. delete object from array java
  11. delete object from json array
  12. delete object from s3 bucket java
  13. delete object from arraylist java
  14. delete object from dict python
  15. delete object from array typescript
  16. delete object from array python
  17. delete object from list c#
  18. delete object from s3 boto3
  19. delete object from workspace r
  20. delete object from json javascript

There is a public website with this in the source: </div><script type="text/rocketscript"> function calculateIndexIncome() { var khs = $('#t9').val(); var btcusd = $('#t9_1').val()...

There is a public website with this in the source: </div><script type="text/rocketscript"> function calculateIndexIncome() { var khs = $('#t9').val(); var btcusd = $('#t9_1').val()...

  1. extract string html python
  2. extract string from html
  3. extract string from html java
  4. extract string between html tags
  5. extract text from html string
  6. extract text from html string python
  7. python extract string between html tags
  8. javascript extract string from html
  9. extract text from html string javascript
  10. extract text from html string c#
  11. extract body from html string
  12. bash extract string from html
  13. extract data from html string
  14. c# extract string from html
  15. extract value from html string
  16. php extract string from html
  17. extract text from html string java
  18. extract text from html string using jquery
  19. regex extract string from html
  20. extract json string from html

<html dir = rtl> <head> <title> </title> <meta HTTP-EQUIV="Content-language" CONTENT="ar"> <script type="javascript"> function d(...

<html dir = rtl> <head> <title> </title> <meta HTTP-EQUIV="Content-language" CONTENT="ar"> <script type="javascript"> function d(...

  1. check text html ratio
  2. checkbox text html
  3. check input text html
  4. sublime text check html syntax
  5. javascript check html text
  6. jasmine check html text
  7. sublime text check html
  8. check if text is html
  9. check if text is html c#
  10. check if text contains html
  11. check if text has html tags
  12. html check text length
  13. check if text contains html tags
  14. check if text contains html c#
  15. check if text is html swift
  16. js check text is html
  17. check bold text in html
  18. php check text html

I have a code, in three.js in console it says : DEPRECATED: Matrix4's .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead. But I have ...

I have a code, in three.js in console it says : DEPRECATED: Matrix4's .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead. But I have ...