Ravi Ravi - 5 months ago 13
Javascript Question

JQuery append value set null before setting another

here I'm using bootstrap modal. When it popup I set a title dynamically by combining existing value (Upload Your File).

<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel" style="font-size: 130%">Upload Your File </h4>

here is my function

clearBn.on("click", function(){
var link = $(this).attr('href');
var hashPosition = link.indexOf('#'); //Get the position of '#'
var product = link.substring(hashPosition + 3);
$(".modal-header #myModalLabel").after( product );

Here I'm doing is split value in the
and set that value to
. Then I again do that it shows the previous appended value and new value like this

1st time:

Upload Your File


2nd time:

Upload Your File


Here I want is clear ABC and put XYZ while Upload Your File text stay remain there


Hope this will be helpful

var _newText = "Upload Your File "+product
$(".modal-header #myModalLabel").text(_newText);

else you can modify the HTML and keep a specific DOM element to show the file name. Then select that DOM & just put product as text in that specified DOM