My answer is a bit later than the other posts, but I decided to put it here to show,
how to define a new language (Javascript in the example) and how to emphasize only part of the code as the OP wants. I have also used alsoletter
(as the other examples).
\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\gdef\emphasis#1{\lstset{emph={write,void,writeln,Hello,#1},
emphstyle={\ttfamily\textcolor{red}}}}
\begin{document}
\lstdefinelanguage{JavaScript} {
morekeywords={
break,const,continue,delete,do,while,export,for,in,function,
if,else,import,in,instanceOf,label,let,new,return,switch,this,
throw,try,catch,typeof,var,void,with,yield,
},
sensitive=false,
morecomment=[l]{//},
morecomment=[s]{/*}{*/},
morestring=[b]",
morestring=[d]',
alsoletter={.}
}
\lstset{
%frame=tb,
framesep=5pt,
basicstyle=\normalsize, %\ttfamily,
showstringspaces=false,
keywordstyle=\ttfamily\color{blue},
identifierstyle=\ttfamily,
stringstyle=\ttfamily\color{orange},
commentstyle=\color{orange},
rulecolor=\color{black},
xleftmargin=5pt,
xrightmargin=5pt,
aboveskip=\bigskipamount,
belowskip=\bigskipamount,
backgroundcolor=\color{gray!.50},
alsoletter={.}
}
\emphasis{document.createElement, headline.appendChild}
\begin{lstlisting}[language=JavaScript]
// some comments
// about your code
var headline = document.createElement(h1);
var text = document.createTextNode(A text node)
// "offline" node manipulation
headline.appendChild(text);
// adding node to DOM
document.getElementsByTagName("body")[0].appendChild(headline);
\end{lstlisting}
\end{document}
It is always preferable to highlight the part of the code under discussion, rather than color code the whole of the script.