How do I add h1 tag to $('a') in jquery
This code is what displays at the final stage of a jquery quiz. It isn't formatting correctly on my site (maybe battling my CMS a little), but h1 tags are the format I want.
How do I make this also make the a href an h1 tag?
$('<a>')
.addClass('#subscribetext')
.attr('id','subscribetext')
.attr('href','https://www.hamsterdance.org/subscribe')
.html('')
.text('Sign me up!')
.insertAfter('#tweetresult');
javascript jquery
add a comment |
This code is what displays at the final stage of a jquery quiz. It isn't formatting correctly on my site (maybe battling my CMS a little), but h1 tags are the format I want.
How do I make this also make the a href an h1 tag?
$('<a>')
.addClass('#subscribetext')
.attr('id','subscribetext')
.attr('href','https://www.hamsterdance.org/subscribe')
.html('')
.text('Sign me up!')
.insertAfter('#tweetresult');
javascript jquery
Put it in yourhtml()
– vol7ron
Dec 28 '18 at 16:21
You want to wrap theatag or change it? If you change it to anh1the href is no longer a valid attribute.
– chazsolo
Dec 28 '18 at 16:21
You want to addh1tag insideatag or you want to changeatag toh1tag??
– Sushil
Dec 28 '18 at 16:29
add a comment |
This code is what displays at the final stage of a jquery quiz. It isn't formatting correctly on my site (maybe battling my CMS a little), but h1 tags are the format I want.
How do I make this also make the a href an h1 tag?
$('<a>')
.addClass('#subscribetext')
.attr('id','subscribetext')
.attr('href','https://www.hamsterdance.org/subscribe')
.html('')
.text('Sign me up!')
.insertAfter('#tweetresult');
javascript jquery
This code is what displays at the final stage of a jquery quiz. It isn't formatting correctly on my site (maybe battling my CMS a little), but h1 tags are the format I want.
How do I make this also make the a href an h1 tag?
$('<a>')
.addClass('#subscribetext')
.attr('id','subscribetext')
.attr('href','https://www.hamsterdance.org/subscribe')
.html('')
.text('Sign me up!')
.insertAfter('#tweetresult');
javascript jquery
javascript jquery
edited Dec 28 '18 at 16:20
jenil christo
11519
11519
asked Dec 28 '18 at 16:17
Whitney BlankWhitney Blank
84
84
Put it in yourhtml()
– vol7ron
Dec 28 '18 at 16:21
You want to wrap theatag or change it? If you change it to anh1the href is no longer a valid attribute.
– chazsolo
Dec 28 '18 at 16:21
You want to addh1tag insideatag or you want to changeatag toh1tag??
– Sushil
Dec 28 '18 at 16:29
add a comment |
Put it in yourhtml()
– vol7ron
Dec 28 '18 at 16:21
You want to wrap theatag or change it? If you change it to anh1the href is no longer a valid attribute.
– chazsolo
Dec 28 '18 at 16:21
You want to addh1tag insideatag or you want to changeatag toh1tag??
– Sushil
Dec 28 '18 at 16:29
Put it in your
html()– vol7ron
Dec 28 '18 at 16:21
Put it in your
html()– vol7ron
Dec 28 '18 at 16:21
You want to wrap the
a tag or change it? If you change it to an h1 the href is no longer a valid attribute.– chazsolo
Dec 28 '18 at 16:21
You want to wrap the
a tag or change it? If you change it to an h1 the href is no longer a valid attribute.– chazsolo
Dec 28 '18 at 16:21
You want to add
h1 tag inside a tag or you want to change a tag to h1 tag??– Sushil
Dec 28 '18 at 16:29
You want to add
h1 tag inside a tag or you want to change a tag to h1 tag??– Sushil
Dec 28 '18 at 16:29
add a comment |
2 Answers
2
active
oldest
votes
Use .append() and not .text()
If you use .text('<h1>Sign me up!</h1>') it will display <h1>Sign me up!</h1>
but if you use .append('<h1>Sign me up!</h1>') it will display
Sign me up!
$('<a>')
.addClass('subscribetext')
.attr('id','subscribetext')
.attr('href','https://www.hamsterdance.org/subscribe')
.append('<h1>Sign me up!</h1>')
.insertAfter('#tweetresult');
Demo
$('<a>')
.addClass('subscribetext')
.attr('id','subscribetext')
.attr('href','https://www.hamsterdance.org/subscribe')
.append('<h1>Sign me up!</h1>')
.insertAfter('#tweetresult'); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="tweetresult"></div>
It is still not a valid html since anaelement is an inline element, which shouldn't include a block element likeh1.
– Елин Й.
Dec 28 '18 at 16:26
1
@ЕлинЙ. It is valid in HTML 5
– Carsten Løvbo Andersen
Dec 28 '18 at 16:27
Ok, but it is still semantically ugly.
– Елин Й.
Dec 28 '18 at 16:35
Thank you for teaching me! That worked perfectly @CarstenLøvboAndersen
– Whitney Blank
Dec 28 '18 at 16:37
@WhitneyBlank You are most welcome
– Carsten Løvbo Andersen
Dec 28 '18 at 16:37
add a comment |
You can use .wrap() to wrap the link with another element like h1. You can also set the attributes on creating the element, which has better performance.
$('<a>', {
id: 'subscribetext',
'class': '#subscribetext',
href: 'https://www.hamsterdance.org/subscribe'
})
.text('Sign me up!')
.insertAfter('#tweetresult')
.wrap('<h1></h1>');
why the downvote?
– Елин Й.
Dec 28 '18 at 16:29
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53961344%2fhow-do-i-add-h1-tag-to-a-in-jquery%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Use .append() and not .text()
If you use .text('<h1>Sign me up!</h1>') it will display <h1>Sign me up!</h1>
but if you use .append('<h1>Sign me up!</h1>') it will display
Sign me up!
$('<a>')
.addClass('subscribetext')
.attr('id','subscribetext')
.attr('href','https://www.hamsterdance.org/subscribe')
.append('<h1>Sign me up!</h1>')
.insertAfter('#tweetresult');
Demo
$('<a>')
.addClass('subscribetext')
.attr('id','subscribetext')
.attr('href','https://www.hamsterdance.org/subscribe')
.append('<h1>Sign me up!</h1>')
.insertAfter('#tweetresult'); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="tweetresult"></div>
It is still not a valid html since anaelement is an inline element, which shouldn't include a block element likeh1.
– Елин Й.
Dec 28 '18 at 16:26
1
@ЕлинЙ. It is valid in HTML 5
– Carsten Løvbo Andersen
Dec 28 '18 at 16:27
Ok, but it is still semantically ugly.
– Елин Й.
Dec 28 '18 at 16:35
Thank you for teaching me! That worked perfectly @CarstenLøvboAndersen
– Whitney Blank
Dec 28 '18 at 16:37
@WhitneyBlank You are most welcome
– Carsten Løvbo Andersen
Dec 28 '18 at 16:37
add a comment |
Use .append() and not .text()
If you use .text('<h1>Sign me up!</h1>') it will display <h1>Sign me up!</h1>
but if you use .append('<h1>Sign me up!</h1>') it will display
Sign me up!
$('<a>')
.addClass('subscribetext')
.attr('id','subscribetext')
.attr('href','https://www.hamsterdance.org/subscribe')
.append('<h1>Sign me up!</h1>')
.insertAfter('#tweetresult');
Demo
$('<a>')
.addClass('subscribetext')
.attr('id','subscribetext')
.attr('href','https://www.hamsterdance.org/subscribe')
.append('<h1>Sign me up!</h1>')
.insertAfter('#tweetresult'); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="tweetresult"></div>
It is still not a valid html since anaelement is an inline element, which shouldn't include a block element likeh1.
– Елин Й.
Dec 28 '18 at 16:26
1
@ЕлинЙ. It is valid in HTML 5
– Carsten Løvbo Andersen
Dec 28 '18 at 16:27
Ok, but it is still semantically ugly.
– Елин Й.
Dec 28 '18 at 16:35
Thank you for teaching me! That worked perfectly @CarstenLøvboAndersen
– Whitney Blank
Dec 28 '18 at 16:37
@WhitneyBlank You are most welcome
– Carsten Løvbo Andersen
Dec 28 '18 at 16:37
add a comment |
Use .append() and not .text()
If you use .text('<h1>Sign me up!</h1>') it will display <h1>Sign me up!</h1>
but if you use .append('<h1>Sign me up!</h1>') it will display
Sign me up!
$('<a>')
.addClass('subscribetext')
.attr('id','subscribetext')
.attr('href','https://www.hamsterdance.org/subscribe')
.append('<h1>Sign me up!</h1>')
.insertAfter('#tweetresult');
Demo
$('<a>')
.addClass('subscribetext')
.attr('id','subscribetext')
.attr('href','https://www.hamsterdance.org/subscribe')
.append('<h1>Sign me up!</h1>')
.insertAfter('#tweetresult'); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="tweetresult"></div>Use .append() and not .text()
If you use .text('<h1>Sign me up!</h1>') it will display <h1>Sign me up!</h1>
but if you use .append('<h1>Sign me up!</h1>') it will display
Sign me up!
$('<a>')
.addClass('subscribetext')
.attr('id','subscribetext')
.attr('href','https://www.hamsterdance.org/subscribe')
.append('<h1>Sign me up!</h1>')
.insertAfter('#tweetresult');
Demo
$('<a>')
.addClass('subscribetext')
.attr('id','subscribetext')
.attr('href','https://www.hamsterdance.org/subscribe')
.append('<h1>Sign me up!</h1>')
.insertAfter('#tweetresult'); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="tweetresult"></div>$('<a>')
.addClass('subscribetext')
.attr('id','subscribetext')
.attr('href','https://www.hamsterdance.org/subscribe')
.append('<h1>Sign me up!</h1>')
.insertAfter('#tweetresult'); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="tweetresult"></div>$('<a>')
.addClass('subscribetext')
.attr('id','subscribetext')
.attr('href','https://www.hamsterdance.org/subscribe')
.append('<h1>Sign me up!</h1>')
.insertAfter('#tweetresult'); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="tweetresult"></div>edited Dec 28 '18 at 16:22
answered Dec 28 '18 at 16:21
Carsten Løvbo AndersenCarsten Løvbo Andersen
14.5k82857
14.5k82857
It is still not a valid html since anaelement is an inline element, which shouldn't include a block element likeh1.
– Елин Й.
Dec 28 '18 at 16:26
1
@ЕлинЙ. It is valid in HTML 5
– Carsten Løvbo Andersen
Dec 28 '18 at 16:27
Ok, but it is still semantically ugly.
– Елин Й.
Dec 28 '18 at 16:35
Thank you for teaching me! That worked perfectly @CarstenLøvboAndersen
– Whitney Blank
Dec 28 '18 at 16:37
@WhitneyBlank You are most welcome
– Carsten Løvbo Andersen
Dec 28 '18 at 16:37
add a comment |
It is still not a valid html since anaelement is an inline element, which shouldn't include a block element likeh1.
– Елин Й.
Dec 28 '18 at 16:26
1
@ЕлинЙ. It is valid in HTML 5
– Carsten Løvbo Andersen
Dec 28 '18 at 16:27
Ok, but it is still semantically ugly.
– Елин Й.
Dec 28 '18 at 16:35
Thank you for teaching me! That worked perfectly @CarstenLøvboAndersen
– Whitney Blank
Dec 28 '18 at 16:37
@WhitneyBlank You are most welcome
– Carsten Løvbo Andersen
Dec 28 '18 at 16:37
It is still not a valid html since an
a element is an inline element, which shouldn't include a block element like h1.– Елин Й.
Dec 28 '18 at 16:26
It is still not a valid html since an
a element is an inline element, which shouldn't include a block element like h1.– Елин Й.
Dec 28 '18 at 16:26
1
1
@ЕлинЙ. It is valid in HTML 5
– Carsten Løvbo Andersen
Dec 28 '18 at 16:27
@ЕлинЙ. It is valid in HTML 5
– Carsten Løvbo Andersen
Dec 28 '18 at 16:27
Ok, but it is still semantically ugly.
– Елин Й.
Dec 28 '18 at 16:35
Ok, but it is still semantically ugly.
– Елин Й.
Dec 28 '18 at 16:35
Thank you for teaching me! That worked perfectly @CarstenLøvboAndersen
– Whitney Blank
Dec 28 '18 at 16:37
Thank you for teaching me! That worked perfectly @CarstenLøvboAndersen
– Whitney Blank
Dec 28 '18 at 16:37
@WhitneyBlank You are most welcome
– Carsten Løvbo Andersen
Dec 28 '18 at 16:37
@WhitneyBlank You are most welcome
– Carsten Løvbo Andersen
Dec 28 '18 at 16:37
add a comment |
You can use .wrap() to wrap the link with another element like h1. You can also set the attributes on creating the element, which has better performance.
$('<a>', {
id: 'subscribetext',
'class': '#subscribetext',
href: 'https://www.hamsterdance.org/subscribe'
})
.text('Sign me up!')
.insertAfter('#tweetresult')
.wrap('<h1></h1>');
why the downvote?
– Елин Й.
Dec 28 '18 at 16:29
add a comment |
You can use .wrap() to wrap the link with another element like h1. You can also set the attributes on creating the element, which has better performance.
$('<a>', {
id: 'subscribetext',
'class': '#subscribetext',
href: 'https://www.hamsterdance.org/subscribe'
})
.text('Sign me up!')
.insertAfter('#tweetresult')
.wrap('<h1></h1>');
why the downvote?
– Елин Й.
Dec 28 '18 at 16:29
add a comment |
You can use .wrap() to wrap the link with another element like h1. You can also set the attributes on creating the element, which has better performance.
$('<a>', {
id: 'subscribetext',
'class': '#subscribetext',
href: 'https://www.hamsterdance.org/subscribe'
})
.text('Sign me up!')
.insertAfter('#tweetresult')
.wrap('<h1></h1>');
You can use .wrap() to wrap the link with another element like h1. You can also set the attributes on creating the element, which has better performance.
$('<a>', {
id: 'subscribetext',
'class': '#subscribetext',
href: 'https://www.hamsterdance.org/subscribe'
})
.text('Sign me up!')
.insertAfter('#tweetresult')
.wrap('<h1></h1>');
edited Dec 28 '18 at 16:42
answered Dec 28 '18 at 16:28
Елин Й.Елин Й.
512716
512716
why the downvote?
– Елин Й.
Dec 28 '18 at 16:29
add a comment |
why the downvote?
– Елин Й.
Dec 28 '18 at 16:29
why the downvote?
– Елин Й.
Dec 28 '18 at 16:29
why the downvote?
– Елин Й.
Dec 28 '18 at 16:29
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53961344%2fhow-do-i-add-h1-tag-to-a-in-jquery%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Put it in your
html()– vol7ron
Dec 28 '18 at 16:21
You want to wrap the
atag or change it? If you change it to anh1the href is no longer a valid attribute.– chazsolo
Dec 28 '18 at 16:21
You want to add
h1tag insideatag or you want to changeatag toh1tag??– Sushil
Dec 28 '18 at 16:29