PatrickPDD
PatrickPDD

Reputation: 113

jquery $(this).html(var) not working in IE

HI I a have a var "status" that should be inserted into the anchor tag using the .html in Jquery.

(<a class="status"><span>$status</span></a>) 

This works like a charm in Chrome but not in IE10 or Firefox. I added the console.log at the bottom of this function and it correctly writes the var 'status' as it toggles back and forth in Chrome but NOT in IE or Firefox. There the log writes that the variable is "undefined".

 function clickPrice(ev) {
    pp = $(this).closest('.price-point')
    status = pp.attr('data-status')
    if (status=='active') status = 'inactive'
    else status = 'active'
    pp.addClass('dirty')
    pp.attr('data-status', status)
    $(this).html(status)
    console.log(status)
}

Weird.

Upvotes: 0

Views: 309

Answers (1)

jfriend00
jfriend00

Reputation: 707376

Without seeing an actual functioning block of code in something like a jsFiddle, it's pretty hard for us to know what is behaving differently in different browsers. I would suggest you start with defining your variables locally so you aren't inadvertently messing with other globals:

function clickPrice(ev) {
    var pp = $(this).closest('.price-point');
    var status = pp.attr('data-status');
    if (status === 'active') {
       status = 'inactive';
    } else {
        status = 'active';
    }  
    pp.addClass('dirty').attr('data-status', status);
    $(this).html(status);
    console.log(status);
}

For the best chance of further help, please show us the relevant HTML, the event handler and put it in a functioning jsFiddle. I'd also suggest that you check your browser error console or the debug console to see if there are any relevant script errors that might be interrupting the code before it completes.

Upvotes: 2

Related Questions