1

OK, once again I need help. I have managed to pass a variable in a query string from one page to another using this guys code: http://snipplr.com/users/Roshambo/

That all works great and I can see that it works by using an alert on the second page to test it:

var byName = $.getUrlVar('id');
alert(byName);

However... what I would like to do is take that var and paste it into a css rule, so that this would essentially happen:

div#byName{
    display: block;
}

I've read that using document.write is frowned heavily upon and to be honest, I just don't know what I'm doing. How can I get the div with an id the same as the var to display as a block?

Any help greatly greatly appreciated. I am at wits end with this project! :(

4

3 回答 3

3

你可以试试:

var byName = $.getUrlVar('id');
$("#" + byName).css("display", "block");
于 2010-11-23T16:10:40.270 回答
1

您可以使用 .css() jQuery 命令应用 css 样式

var byName = $.getUrlVar('id'); 
$("#" + byName).css("display", "block");

看:http ://api.jquery.com/css/

或使用 addClass() 并在 css 文件中定义您的样式

var byName = $.getUrlVar('id');
$("#" + byName).addClass("example");

div.example{
    display: block;
}
于 2010-11-23T16:11:05.447 回答
0

Can you just getaway with .addClass('foo') where the class already has the style?

于 2010-11-23T16:10:08.793 回答