Reputation: 56968
I find myself using this method a ton to perform actions based on a anchor tag's URL (with jQuery):
("a").live("click", function(event)
{
event.preventDefault();
var href = $(this).attr("href");
// do something with URL
}
Elsewhere in my app, I've got some tabular data which I'm adding inline edits to. When you double click a <td>
in the <table>
, it makes the data editable (text, date select, etc) and hitting "enter" will make an $.ajax
request to save the new value. My question is, if each one of these <td>
's has a href associated with it, how/where should I store the uri?
For example, a <td>
would have a URL like /articles/field/title/id/5 which I would parse using javascript and send a post using some of the params.
Is this acceptable:
<td href="/articles/field/title/id/5">
And then use the same javascript as above? Or...
Ideas very much welcome.
Upvotes: 0
Views: 409
Reputation: 1997
jQuery optionally has a metadata plugin, where attributes are stored in the class
attribute:
<td class="myClass { myAttrib: 'attrVal', mySecondAttrib: 69 }">
http://plugins.jquery.com/project/metadata
Upvotes: 0
Reputation: 14967
an option would be something like:
<td id="-articles-field-title-id-5">
in the case of not using IDs, "-" Can be any character.
Upvotes: 1
Reputation: 37813
href
is not a valid attribute of the <td>
tag. If you want the contents to be clickable in that manner, wrap the inside in a traditional <a>
tag and handle that as you would any other link.
Upvotes: 3