2
$("label[for='c1pick'] .ui-btn-text").html($("#introdukt").val())

I would like to replace c1pick and #introdukta with variables

Tried the first one the following way:

 whichone="c1pick" 
$("label[for=whichone] .ui-btn-text").html($("#introdukt").val())

but it doesnot work.

Is there a way? How to replace #introdukt reference with a variable, too?

0

2 Answers 2

4
$("label[for=whichone] .ui-btn-text")

supposed to be

$("label[for=" + whichone + "] .ui-btn-text")

This selector

$("label[for=whichone]

tries to select this label <label for="whichone"

When you append the variable

$("label[for=" + whichone + "] it first replaces the variable and then tries to select the element.

Code

var whichone="c1pick",
    intro = "introdukt";

$("label[for=" + whichone + "] .ui-btn-text").html($("#" + intro).val())
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

var whichone = "c1pick";
var intro = "introdukt";
$("label[for='" + whichone + "'] .ui-btn-text").html($("#" + intro ).val());

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.