I have this problem. I want to modify the css of a particular div. That division is being generated dynamically. The output is this:
<div class=" class-name"></div>
Apparently, there is a space before the class name. I tried using:
$(".class-name").html("test");
But my code wont work.
Thanks in advance.
I have this problem. I want to modify the css of a particular div. That division is being generated dynamically. The output is this:
<div class=" class-name"></div>
Apparently, there is a space before the class name. I tried using:
$(".class-name").html("test");
But my code wont work.
Thanks in advance.
Share Improve this question asked Jul 3, 2013 at 6:34 ebalebal 9463 gold badges14 silver badges31 bronze badges 3- Did you try it in the class name without the space? Just so you can be sure that this is the issue. – Uooo Commented Jul 3, 2013 at 6:37
-
2
"Apparently, there is a space before the class name" No, there's a space in the attribute, but the attribute is a space-delimited set of class names. So the class on the element is actually
class-name
(without the space). – T.J. Crowder Commented Jul 3, 2013 at 6:44 - It definitely works with a space, regardless of whether the div is generated dynamically, as long as you run the code after the div exists: jsfiddle/hREVy/1 – nnnnnn Commented Jul 3, 2013 at 6:56
1 Answer
Reset to default 13The space does not matter. You either have not got jQuery loaded or else or not waiting unitl the code is ready.
$(function(){
$(".class-name").html("test");
});
To help you debug for next time, install firebug on firefox and in the console an error might show up.