最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to select a class with a space before the name - Stack Overflow

programmeradmin2浏览0评论

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
Add a ment  | 

1 Answer 1

Reset to default 13

The 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.

发布评论

评论列表(0)

  1. 暂无评论