I am working on a page with jquery. I want to change the text in html dom. But when I try to do this, it removes all the html code under dom. Here you can check jsfiddle:
http://jsfiddle.net/msxpwr5p/
html markup
<div class="container"> <h1 class="page-header">Edit Profile <div class="broadcast"> <button id="button1" class="btn btn-success"><i class="icon-bullhorn"> </i>button1</button> </div> <div class="broadcast"> <button id="button2" class="btn btn-success"><i class="icon-bullhorn"></i>button2</button> </div> </h1> </div>
Jsfile
$("#button2").on('click', function(e){ $(".page-header").text("another text"); });
I just want to change the text Edit profile . I do not want to delete my buttons. What is wrong with my code?
I know that I inserted several div into my h1 , this is intentional. I want to know if there are any solutions for this kind of situation? suppose i create
<div id="hello"> Hello <a href=#></a> <button>text</button> <div>
In this situation, if I want to change the text "hello". What should I do?
user3957766
source share