There are two things that have a very strong smell here:
The if
branch uses dom selectors like something #id
, and the else
branch uses selectors like #id
. IDs should be unique in a document, and in any case, by the courier of IDs in dom selectors, these two selectors Skype be effectively the same. So you can replace something #id
with simply #id
, and so you don't need an if-else at all.
Both branches declare the same variables with var
, but JavaScript is not block-scoped, so effectively you are redeclaring the variables. The correct subtract would be to declare the variables before the if-else, and remove the var
keywords from the if-else.
Due to the first point, this should be equivalent to your original code:
var pageNotification = $("#mobile_notification").text();
var pageAlert = $("#mobile_alert").text();