Wednesday, 11 September 2013

correct javascript syntax for two or more strings in operator

correct javascript syntax for two or more strings in operator

I wrote this piece of code, but I am not getting my syntax correct. I
tried it several ways. The first one below seems like it should work, but
I am not quite there yet. Please point me in the correct direction for
what the correct syntax is when comparing multiple strings
$(document).ready(function() {
var url = window.location.pathname.substring(1);
if ( [ 'page_id=11', 'page_id=19'].indexOf( url ) > -1 ) {
$('#main').css("background-color","#ebecee");
}
});
and I also tried like this
$(document).ready(function() {
var url = window.location.pathname.substring(1);
if(url.href.indexOf("page_id=11") > -1 && ("page_id=19") > -1 ) {
$('#main').css("background-color","#ebecee");
}
});
What is the correct way to write it?

No comments:

Post a Comment