Click here to Skip to main content
16,012,508 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
JavaScript
var purchas_probability=$("<label></label>")
                                                 .prop("id",i)
                                                 .text(output[i].count1"/"output[i].total_purchase);
                                                 .css({
                                                  width:'40px',
                                                  height:'40px'
                                                      });


i am getting some value in count1 and total_purchase in label it should display like this "1/3" i am getting error when i tried to do this and css should also work for it
Posted
Updated 25-Jun-14 3:36am
v3
Comments
Kornfeld Eliyahu Peter 25-Jun-14 9:33am    
And what the error is?
Nandhini Devi 25-Jun-14 9:35am    
its not showing js file and its not showing error in console

You get this error because you just put the string "/" between the two variables. You need to concatenate them:
JavaScript
output[i].count1 + "/" + output[i].total_purchase

If it is still not working, then you probably have not yet appended the element. Use the jQuery append[^] or appendTo[^] to do that.

Also, you need to remove the semicolon after the text method:
JavaScript
ar purchas_probability=$("<label></label>")
                                                 .prop("id",i)
                                                 .text(output[i].count1"/"output[i].total_purchase)  // here shouldn't be a semicolon
                                                 .css({
                                                  width:'40px',
                                                  height:'40px'
                                                      });
 
Share this answer
 
v3
Comments
Nandhini Devi 25-Jun-14 9:38am    
not working
Thomas Daniels 25-Jun-14 9:42am    
Then you probably have not appended the element. I updated my answer.
Nandhini Devi 25-Jun-14 9:44am    
i did but still not working
Thomas Daniels 25-Jun-14 9:45am    
Can you please provide the full code that you have now?
Nandhini Devi 25-Jun-14 9:46am    
var purchas_probability=$("<label></label>")
.prop("id",i)
.text(output[i].count1+"/"+output[i].total_purchase);
.css({
width:'40px',
height:'40px'
});
$("#id").append(purchas_probability);
JavaScript
.text(output[i].count1"/"output[i].total_purchase);

All the problems are here:
1. if you want concatenate variables and strings you should use +
JavaScript
.text(output[i].count1 + "/" + output[i].total_purchase);

2. you have a ; at the end of this line - remove it!
JavaScript
.text(output[i].count1 + "/" + output[i].total_purchase);
 
Share this answer
 
Comments
Nandhini Devi 25-Jun-14 10:02am    
do you know how to add dynamic button
Kornfeld Eliyahu Peter 25-Jun-14 10:03am    
Google for 'jquery add button dynamically'...
Nandhini Devi 25-Jun-14 10:08am    
var shoplink=$("<button></button>")
.prop("id",i)
.val("view more")
.css({
width: '20px'
height: '20px'
});
i tried this but its not working
Kornfeld Eliyahu Peter 25-Jun-14 11:48am    
Not working? You have to explain that...
Nandhini Devi 26-Jun-14 0:08am    
button is not displaying when i used this code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900