【发布时间】:2017-01-15 01:24:12
【问题描述】:
如何找到name= 值等于URL 中的哈希值的锚元素,然后将open 类添加到下一个div 元素?
if(window.location.hash) {
var hash = window.location.hash.substring(1); //Puts hash in variable, and removes the # character
console.log(hash);
// Find the anchor element where the value is equal to the has in the URL, then add '.open' class to the next div element.
$("a[name=$hash]").addClass('open'); //WRONG SYNTAX! How do I write this?
}
【问题讨论】:
标签: jquery hash find anchor addclass