Reputation: 3410
I have an aspx page title tag like the following :
<title> XXXX-content page title </title>
I need to dynamically set the title tag of my Page from code behind like the following:
<title> <span itemprop="name"> XXXX-content page title</span> </title>
My question is : How do I dynamically insert(wrap) the "XXXX-content page title" part of the title in a span tag?? I tried doing this :
Page.Title = "<span itemprop=\"name\">"+ XXXX-content page title + "</span>";
but it renders the span tag within the quotations. How can I do this without using Jquery?
Upvotes: 1
Views: 1108
Reputation: 201798
You can put the itemprop
attribute directly on the title
element:
<title itemprop="name">XXXX-content page title</title>
However, mostly the page contains, or should contain, a main heading that is to appear as part of the page. It is probably more common to have the relevant text there. And within that heading, you can use inner markup:
<h1>span itemprop="name">The key part of the heading</span> more stuff</h1>
In general, you need not add span
elements for microdata, if there is an element in markup that contains just the text to be used.
Upvotes: 1
Reputation: 21996
all you need to do is ...
<title id="title" runat="server"></title>
... and then in your codebehind ...
title.Text = "I set this title in code-behind";
Upvotes: 0
Reputation: 3290
I believe you can't add span
tag between title tag.
For what reason did you need to add span
?
Upvotes: 1
Reputation: 125650
Title tag cannot include other HTML tags? Following to the HTML spec:
Titles may contain character entities (for accented characters, special characters, etc.), but may not contain other markup (including comments).
Upvotes: 1