最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - trying to access rel attribute of <a> using javascript - Stack Overflow

programmeradmin0浏览0评论

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 trigger 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???

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 trigger 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???

Share Improve this question edited Jan 13, 2011 at 19:02 Pekka 450k148 gold badges986 silver badges1.1k bronze badges asked Jan 13, 2011 at 19:00 AnubhavAnubhav 792 silver badges9 bronze badges 2
  • 7 You should accept answers to your questions. – SLaks Commented Jan 13, 2011 at 19:04
  • So you want to place the gb_page... into the rel attribute programmatically? – Marnix Commented Jan 13, 2011 at 19:05
Add a ment  | 

3 Answers 3

Reset to default 4

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/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 acplished quite cleanly by using the .attr() method:

$('a').attr('rel', 'gb_page_center[450, 450]');
发布评论

评论列表(0)

  1. 暂无评论