Question

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! :(

Was it helpful?

Solution

You can apply css style using the .css() jQuery command as

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

Look at: http://api.jquery.com/css/

or use addClass() and define your style in css file

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

and

div.example{
    display: block;
}

OTHER TIPS

You can try:

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top