简体   繁体   中英

How to set span value inside of anchor tag

I have anchor tag in which some class bind dynamically on page load, I need to change the value of span tag inside anchor tag below is my code:

<a id="aView" km-button km-state-active" data-badge="0" href="#view" data- icon="globe" data-role="tab">
    <span class="km-icon km-globe"></span>
    <span class="km-badge">0</span>
    <span class="km-text">view</span>
</a>

I need to change "km-badge" value using JavaScript or jQuery need help

$("#aView .km-badge").text("blablabla");

2nd:

var el = $("#aView .km-badge"); // define variable that points to DOM object
el.removeClass("km-badge"); // remove class from object
el.text("blablabla"); // change attribute "text" of object
el.addClass("km-badge"); // add class to object

with javascript you can do,

<body>
<script type="text/javascript">
document.getElementById("aView").innerHTML = "writetexthere";
</script>
</body>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM