Yahoo Quotes

by ravimallya

HTML

<div class="container-fluid">
        <span id="quoteName"></span>
        <br />
        <span id="curSymbol"></span><span id="quotePrice"></span>
        <br />
        <span id="priceChange"></span><span id="arrow"></span>
    </div>

JavaScript

var qryURL = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22BMRN%22)&env=store://datatables.org/alltableswithkeys";
        function getYahooQuotes() {
            $.ajax({
                type: "GET",
                url: qryURL,
                dataType: "xml",
                success: function (xml) {
                    $(xml).find('quote').each(function () {
                        $('#quoteName').text($(this).attr('symbol'));
                        $('#curSymbol').text('$');
                        $('#quotePrice').text($(this).find('LastTradePriceOnly').text());
 
                        var valChange = parseFloat($(this).find('Change').text()).toFixed(2);
                        $('#priceChange').text(valChange);
                        if (valChange > 0) {
                            $('#arrow').text('▲').css('color', 'green');
                            $('#priceChange').css('color', 'green')
                        }
                        if (valChange < 0) {
                            $('#arrow').text('▼').css('color', 'red');
                            $('#priceChange').css('color', 'red')
                        }
                        if (valChange === 0) {
                            $('#arrow').text('=');
                        }
                    });
                },
                error: function (error) {
                    console.log(error);
                }
            });
        }
        
        getYahooQuotes();