[英]How can I use the attribute selector with a variable?
I need to use this form because it can handle spaces in my element ID. 我需要使用此表单,因为它可以处理元素ID中的空格。
$("div[id='content Module']").whatever();
However I need 'content Module' replaced with a variable? 但是我需要将“内容模块”替换为变量吗?
I tried 我试过了
$("div[id=" + my_var + "']").whatever();
but this did not work 但这没有用
You're missing a ' 您缺少“
$("div[id=" + my_var + "']").whatever();
Should be 应该
$("div[id='" + my_var + "']").whatever();
try this $("div[id='" + my_var + "']").whatever();
试试这个
$("div[id='" + my_var + "']").whatever();
you forgot the open Apostrof 你忘记了开放的使徒
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.