Setting variables inside if / else-if statment blocks
I don't know what the purpose of declaring your variable within your if statement is supposed to be here. For readability, I would declare those variables at the beginning of your function, like so:

function test() {
    var x = 3, 
        msg, 
        state;
    if (x &gt; 5) {
        msg = "m", state = "d";
    } else if (x &lt; 5) {
        msg = "a", state = "d";
    } else {
        msg = "e", state = "n";
    }
    $('#id1').removeClass().addClass(state);
    $('#id2').html("Some text " + msg + " and more text.");
    $('#id3').attr('title', "Different text " + msg + " still different text.");
}


That being said, I don't know a reason why you couldn't do so; it most depends on readability and the best practices you are following.