February 26, 2013

empty() then run the rest of the funtion

Question by ndesign11

I have some json that’s loaded into li.ui-state-default pending user entry.

The user can then enter a new entry. I want it to empty li.ui-state-default everytime a new entry is loaded but it seems to just stay empty.

//data for DOM
var timeout = '';
$('.call-json').keyup(function () {
    clearTimeout(timeout);
    var val = this.value;
    timeout = setTimeout(function () {
        $('.ui-state-default').empty();
        $.getJSON('json/' + val + '.json', function (data) {
            // load data

            var items = [];
            for (key in data[0].attributes) {
                if (key.match('.stat.prop.type')) {
                    items.push(data[0].attributes[key])
                }
            };

            displaySortLabel(items, "type-details");

        function displaySortLabel(items, parentClass) {
                $('<span/>', {
                    'class': 'el-data',
                    html: items.join('')
                }).hide().fadeIn().appendTo('.' + parentClass + ' .sort-label');
            }

Answer by Starx

$('li.ui-state-default').html(''); //empty it like this

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!