[英]javascript jquery html - how to assign the title attribute to a .class
I have a div that holds the results that is retrieved by ajax. 我有一个div,它保存由ajax检索的结果。 Depends on the result, the div will be assigned a different css class.
根据结果,将为div分配不同的CSS类。 I want to attach the title attribute to the classes so that class 1 will show the title 1, and class 2 will show the title 2. My routine is somewhat complicated, so assigning the
attr('title','xxx')
each time I switch the class has not been successful. 我想将title属性附加到类上,以便类1将显示标题1,而类2将显示标题2。我的例程有些复杂,因此每次都分配
attr('title','xxx')
我切换班没有成功。
Is it possible to attach the title to a css class like the pseudo code below? 是否可以将标题附加到css类,如下面的伪代码?
TIA TIA
.class1
{
title: 'class1';
}
.class2
{
title: 'class2';
}
Your explanation is a bit unclear, but you may want to try adding live()
to the chain before you call attr(title,xxx)
. 您的解释还不清楚,但是您可能需要在调用
attr(title,xxx)
之前尝试将live()
添加到链中。 AJAX requests (asynchronous ones) load data into the DOM after the onReady function executes your script, so whatever selector you are using may be invalid at the time the script executes. 在onReady函数执行脚本之后,AJAX请求(异步请求)将数据加载到DOM中,因此您使用的任何选择器在脚本执行时都可能无效。
No, it isn't. 不,不是。
CSS is designed to describe the presentation of a DOM, not its content (even though it dips a toe into that area with content
). CSS旨在描述DOM的表示形式 ,而不是描述其内容(即使它通过
content
进入该区域也是如此)。
您将仅需使用attr(title,xxx)
即使您的例程很复杂,也可以使用jquery选择器在第1行或第2行中进行操作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.