How to append a value in title of HTML tooltip

Viewed 777

I have a code in HTML like this.

<input type="text" 
       id="cableless_plans_limit" 
       class="form-control list-text"
       onkeypress="return isNumber(event,127,1)" 
       placeholder="Plan No"
       data-toggle="tooltip" 
       data-placement="top"
       title="Cableless Plan No should be a integer less than" 
/>

and a JavaScript in which "maxCblsPlans" is coming from database

$('#cableless_plans_limit').attr("title", +response.maxCblsPlans);

How can I append this to HTML title so that I can get an output like when I Click in a text box it should show a tooltip like

Cableless Plan No should be a integer less than 7 ("maxCblsPlans" is 7)

2 Answers

By using $('#cableless_plans_limit').attr("title"); you can get the value of the title parameter.

$('#cableless_plans_limit').attr("title",     
   $('#cableless_plans_limit').attr("title") +response.maxCblsPlans);

Try getting the old value into a variable & then append the new value & assign it back

var title = $('#cableless_plans_limit').attr("title");
title += response.maxCblsPlans;
$('#cableless_plans_limit').removeAttr("title")
$('#cableless_plans_limit').attr("title", title);

Hope this will help you.

Related