I’ve tried adding a variable within the selector, but no dice. I’ve tried a couple of different ways.
Ex1:
function makeDerp() {
var num = 1;
$("myDiv" + num).append("<h1>derp</h1>");
}
Ex2:
function makeDerp() {
var num = 1;
var thing = $("myDiv" + num);
thing.append("<h1>derp</h1>");
}
Ex3:
function makeDerp() {
var num = 1;
var thing = "$('myDiv" + num + "')";
thing.append("<h1>derp</h1>");
}
On all 3, I get nada. Any ideas? Something with my syntax or am I missing a step?
Your first and second examples will work fine. The problem is your selector, which is currently looking for an element of type
myDiv. I’m guessing you meant it to be anidselector (perhaps a class selector, or something else entirely, but the idea is the same):Your third example will not work.
thingcontains a string literal, and that won’t have anappendmethod so you’ll get a TypeError.