1

Is it possible to expand existing html tag? For example i want add type of <link> tag and make some action on this type

<link rel="stylesheet" type="new-type" href="theme.css">

and when we have link with new type make some action automatically?

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
Filip
  • 105
  • 11
  • 1
    If you can use jQuery then it would be very simple. http://stackoverflow.com/questions/918792/use-jquery-to-change-an-html-tag – DDan Nov 16 '15 at 09:28
  • 1
    The best answer to this question will depend on what type of action you have in mind. For better answers, please describe your desired outcome in less abstract terms. – David Hedlund Nov 16 '15 at 09:31

3 Answers3

1

Yes, you can. The best to do this is to use the data- attributes. Those are skipped by any validator so safe to use for your own purpose:

<link id="someId" rel="stylesheet" type="new-type" href="theme.css" data-special="true">

If you use jQuery, you can even get it out easy:

var x = $("#someId").data("special");
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
0

You can use insertAdjacentHTML. In the example below the new element will be inserted after the element defined by `getElementById("link"):

var element = document.getElementById("link");
var newElement = '<link rel="stylesheet" type="new-type" href="theme.css">'
element.insertAdjacentHTML( 'afterend', newElement )

See this link for the full documentation: https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentHTML

Alex
  • 21,273
  • 10
  • 61
  • 73
0

yes you can. you have to do a simple modification to your code like below-

<link rel="stylesheet" data-type="new-type" href="theme.css">
user-4653387
  • 305
  • 1
  • 4
  • 17