I am using an javascript overlay in my site for my subscription form. I have loaded the code for overlay from net. It is in javascript. Now the thing is to tri开发者_运维问答gger the overlay function using a link i need put some value under <a rel="">
.
more specifically, <a href="subscribe.php" rel="gb_page_center[450, 450]">click</a>
But i dont want to put a tag instead i want to link to the subscription page using javascript function. Now my problem is how or where do i put the value under 'rel' attribute in my javascript to get the same result???
Like this:
<a href="#;" onclick="alert(this.rel);return false;" rel="bob">A</a>
If you want to use plain JS without jQuery, try setAttribute: https://developer.mozilla.org/en/DOM/element.setAttribute
Give your tag an id attribute and then you can add:
document.getElementById("your_id").setAttribute("rel", "gb_page_center[450, 450]");
Using jQuery, this can be accomplished quite cleanly by using the .attr() method:
$('a').attr('rel', 'gb_page_center[450, 450]');
精彩评论