The reason for that is the id of txtSearch change when you add it to the Master Page id will be something like this “ctl00$ContentPlaceHolder1$txtSearch”. So Jquery is not able to find control with id “$txtSearch”. You can check view source of your page. You can select elements by a partial id in JQuery with syntax like below.
$("input[id*= txtSearch]")
Please refer this link for more information
selecting elements by a partial id[
^]