{"action":"opened","issue":{"url":"https://api.github.com/repos/aspnet/Razor/issues/311","labels_url":"https://api.github.com/repos/aspnet/Razor/issues/311/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Razor/issues/311/comments","events_url":"https://api.github.com/repos/aspnet/Razor/issues/311/events","html_url":"https://github.com/aspnet/Razor/issues/311","id":58404625,"number":311,"title":"Allow tag helpers to target elements by attribute","user":{"login":"DamianEdwards","id":249088,"avatar_url":"https://avatars.githubusercontent.com/u/249088?v=3","gravatar_id":"","url":"https://api.github.com/users/DamianEdwards","html_url":"https://github.com/DamianEdwards","followers_url":"https://api.github.com/users/DamianEdwards/followers","following_url":"https://api.github.com/users/DamianEdwards/following{/other_user}","gists_url":"https://api.github.com/users/DamianEdwards/gists{/gist_id}","starred_url":"https://api.github.com/users/DamianEdwards/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DamianEdwards/subscriptions","organizations_url":"https://api.github.com/users/DamianEdwards/orgs","repos_url":"https://api.github.com/users/DamianEdwards/repos","events_url":"https://api.github.com/users/DamianEdwards/events{/privacy}","received_events_url":"https://api.github.com/users/DamianEdwards/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/aspnet/Razor/labels/TagHelper","name":"TagHelper","color":"bfdadc"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-02-20T20:15:09Z","updated_at":"2015-02-20T20:15:09Z","closed_at":null,"body":"Currently, tag helpers target elements by element name. They should also be able to target elements via attribute names. This would allow tag helpers to easily target existing elements in a more aspect oriented fashion. It also has the benefit of potentially reducing overhead for said tag helpers, because they're only attached to elements that explicitly opt-in via the attribute.\r\n\r\nSome of the MVC tag helpers we've already written would utilize this feature, e.g. validation summary.\r\n\r\nA tag helper should be able to target elements by element name(s), attribute name(s), or both. They should be able to specify their targets in groups to allow for both AND and OR combinations.\r\n\r\nAttribute names should support partial wild-cards, e.g. `asp-param-*`.\r\n\r\n### Examples\r\n\r\n``` C#\r\n// This tag helper will run on <loc> elements and any other element where the 'asp-loc' attribute is present\r\n[TargetElement(\"loc\")]\r\n[TargetElement(attributes = \"asp-loc\")]\r\npublic class LocTagHelper : TagHelper\r\n{\r\n    ...\r\n}\r\n\r\n// This tag helper will run on <cache> elements and any other element where the 'asp-cache' attribute is present\r\n[TargetElement(\"cache\")]\r\n[TargetElement(attributes = \"asp-cache\")]\r\npublic class CacheTagHelper : TagHelper\r\n{\r\n    ...\r\n}\r\n\r\n// This tag helper will run on <environment> elements where the 'names' attribute is present, and any other element where the 'asp-environment-names' attribute is present\r\n[TargetElement(\"environment\", attributes = \"names\")]\r\n[TargetElement(attributes = \"asp-environment-names\")]\r\npublic class EnivronmentTagHelper : TagHelper\r\n{\r\n    ...\r\n}\r\n\r\n// This tag helper will run on <input> elements where the 'asp-for' attribute is present\r\n[TargetElement(\"input\", attributes = \"asp-for\")]\r\npublic class InputTagHelper : TagHelper\r\n{\r\n    ...\r\n}\r\n\r\n// This tag helper will run on <div>, <p>, <ul>, and <ol> elements where the 'asp-validation-summary' attribute is present, and on <validation-summary> elements\r\n[TargetElement(\"div,p,ul,ol\", attributes = \"asp-validation-summary\")]\r\n[TargetElement(\"validation-summary\")]\r\npublic class ValidationSummaryTagHelper : TagHelper\r\n{\r\n    ...\r\n}\r\n\r\n// This tag helper will run on any element where both the 'asp-one' and 'asp-two' attributes are present\r\n[TargetElement(attributes = \"asp-one,asp-two\")]\r\npublic class SampleTagHelper : TagHelper\r\n{\r\n    ...\r\n}\r\n\r\n// This tag helper will run on any element where at least one attribute beginning with 'asp-param-' is  present\r\n[TargetElement(attributes = \"asp-param-*\")]\r\npublic class SameParamTagHelper : TagHelper\r\n{\r\n    ...\r\n}\r\n```"}}