Here I have code to convert number(rating) into stars using http://wbotelhos.com/raty, http://wbotelhos.com/raty/lib/jquery.raty.min.js
I create an jsfiddle: http://jsfiddle.net/3SXKe/4/
// mocking your supposed "place" variable
var place = { name: "James Cook Hotel Grand Chancellor", rating: "3.6",
photos: [{ getUrl: function () { return "https://lh6.googleusercontent.com/-T0_fJX5zza0/UdSnOaucZvI/AAAAAAAAAFc/gQhK3IbHJfY/w50-h50-s0/Small%2BLogo.png" } }]
}
var photo = place.photos[0].getUrl({
'maxWidth': 50,
'maxHeight': 50
});
var elemenatDiv = $('<div>').addClass('elemenat');
var draggableDiv = $('<div>').addClass('draggable');
var logo = $('<img>').css({'margin-left': '3px', 'margin-top': '5px'})
.attr('src', photo).attr('width', 46).attr('height', 42)
var sideClick = $("<a>").addClass('side_click').attr('href', '#')
.text(place.name + place.rating);
var elementnameDiv = $('<div>').addClass('elementname');
var star = $('#star').raty({ score: place.rating });
elemenatDiv.append(draggableDiv.append(logo));
elemenatDiv.append(elementnameDiv.append(sideClick).append(star));
$("#side_bar").append(elemenatDiv);
$(sideClick).on("click", function () {
markers[i].modalWindow_.getDetails(markers[i].place_);
});
and I use first: var star = $('#star').raty({ score: place.rating });
and after that append elemenatDiv.append(elementnameDiv.append(sideClick).append(star));
but star rating won't to show when render html code?
I try different solution but I dont know where is error?
This line is the problem:
var star = $('#star').raty({ score: place.rating });
You are trying to select a DOM element by ID (#star
), but there is no element in the DOM.
You need to an inject a DIV with an ID of star
into the DOM.