I want to add a new attribute to my HTML dynamically, but I can’t figure out how to do this;
I have some Facebook like button code, where I want to add a “data-url” attribute if the Url property in my model is specified.
I’ve tried a couple of things but this is what my code looks like now:
<a href="https://twitter.com/share" class="twitter-share-button" @if (!string.IsNullOrEmpty(Model.Url)) { data-url="@Model.Url" } data-text="@Model.TweetText" data-count="vertical" data-via="avalaxy">Tweet</a><script type="text/javascript" src="//platform.twitter.com/widgets.js"></script>
This does not work. So how do I do this?
I believe you want to use the
<text>tag, with something like: