开发者

Is there a way to link to a <p> that has a unique "uri" attribute?

I am trying to link to a specific paragraph in a website that has added a "uri" attribute to each of their paragraphs. ie.:

<p uri="/level1/leve2/pagename.p5">

Any way to do that?

(To clarify, this is not a site that I have any control over or can change beyond suggesting that they change, just wondering if there is a way to link to the way they currently开发者_如何学编程 do it.)


No. It is a non-standard attribute, browsers do nothing with it.

If you want to link to an element, then you should give it an id and specify:

http://example.com/example.html#theElementId

You could, in theory, add some JavaScript to the page that would search through all the elements in the page for ones with a uri attribute and convert them to id attributes, but having a real HTML document in the first place would be better.


If you have no control over the page then, short of writing a browser plugin and making everyone use it, you cannot achieve this.


Using jQuery you could do something like pull the attribute value from URI

$('p[uri]').attr('uri');

jsfiddle.net example here:

http://www.jsfiddle.net/vNtTs/


You could use custom data attributes, as such:

<p id="myId" data-uri="...">

If you have more than one <p> then it's best to give it a unique id. You can use jQuery to reference the attribute as such:

$("#myId").data("uri")

And that would be perfectly legitimate and most browsers support custom data attributes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜