How do I add h1 tag to $('a') in jquery












0















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');









share|improve this question

























  • 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 add h1 tag inside a tag or you want to change a tag to h1 tag??

    – Sushil
    Dec 28 '18 at 16:29
















0















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');









share|improve this question

























  • 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 add h1 tag inside a tag or you want to change a tag to h1 tag??

    – Sushil
    Dec 28 '18 at 16:29














0












0








0








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');









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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 add h1 tag inside a tag or you want to change a tag to h1 tag??

    – Sushil
    Dec 28 '18 at 16:29



















  • 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 add h1 tag inside a tag or you want to change a tag to h1 tag??

    – 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












2 Answers
2






active

oldest

votes


















1














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>








share|improve this answer


























  • 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





    @ЕлинЙ. 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



















-1














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>');





share|improve this answer


























  • why the downvote?

    – Елин Й.
    Dec 28 '18 at 16:29











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
});


}
});














draft saved

draft discarded


















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









1














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>








share|improve this answer


























  • 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





    @ЕлинЙ. 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
















1














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>








share|improve this answer


























  • 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





    @ЕлинЙ. 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














1












1








1







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>








share|improve this answer















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>






share|improve this answer














share|improve this answer



share|improve this answer








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 an a element is an inline element, which shouldn't include a block element like h1.

    – Елин Й.
    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






  • 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













-1














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>');





share|improve this answer


























  • why the downvote?

    – Елин Й.
    Dec 28 '18 at 16:29
















-1














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>');





share|improve this answer


























  • why the downvote?

    – Елин Й.
    Dec 28 '18 at 16:29














-1












-1








-1







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>');





share|improve this answer















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>');






share|improve this answer














share|improve this answer



share|improve this answer








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



















  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Mossoró

Error while reading .h5 file using the rhdf5 package in R

Pushsharp Apns notification error: 'InvalidToken'