2

On a website that I am maintaining, I have many code lines like the following one:

<strong>doi</strong>
<a href="http://website/reference/" target="_blank">reference</a>

where "website" is an actual website address and "reference" is a number which depends on each entry of this type (while the website address is always the same). In html/ccs; is it possible to create a command, let's call it doi such that instead of always writing the two lines above, I would equivalently write

<doi>reference</doi>
6
  • 2
    There are no such things as commands in HTML or CSS. Commented Nov 5, 2015 at 2:46
  • I see. There is no way I can simplify the way I write the initial information then. Too bad. Commented Nov 5, 2015 at 2:50
  • 1
    I guess you could use a PHP function. Commented Nov 5, 2015 at 2:57
  • Or XSLT. Or even a JavaScript function, as long as you are sure that the user always has JavaScript enabled. Commented Nov 5, 2015 at 8:38
  • What exactly are you trying to accomplish here? Do you want to have an a tag that creates a default url? Or do you want your links to be bolded (like the strong tag). I think what you're probably looking for is a web component type thing. Commented Nov 18, 2015 at 2:33

1 Answer 1

1

No it's not possible using just html/css, but it is possible using javascript/jquery or a javascript framework, like angularjs.

Here's an example using jquery: https://jsfiddle.net/partypete25/31dzyjgL/

<!-- HTML -->
<doi>121</doi>

<!-- JavaScript -->
$("doi").each(function(){
    var ref = $(this).text();
    $(this).replaceWith( "<strong>doi</strong><a href='http://website/"+ref+"/' target='_blank'>reference</a>" );
});

So the script will look for all of your custom "doi" tags, and replace them with the fleshed out label+link with the dynamic reference.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.