Step 1 - Include SP Services in your javascript file.
<script type="text/javascript" src="../../SiteAssets/jquery.SPServices-2014.02.min.js"></script>
Step 2 -
var clientContext = SP.ClientContext.get_current();
var website = clientContext.get_web();
clientContext.load(website);
var items = SP.ListOperation.Selection.getSelectedItems(clientContext);
var k;
var idList = new Array();
for (k in items) {
var thisID = items[k].id;
}
Here , "thisID" will give you the selected item's ID on the View.
<script type="text/javascript" src="../../SiteAssets/jquery.SPServices-2014.02.min.js"></script>
Step 2 -
var clientContext = SP.ClientContext.get_current();
var website = clientContext.get_web();
clientContext.load(website);
var items = SP.ListOperation.Selection.getSelectedItems(clientContext);
var k;
var idList = new Array();
for (k in items) {
var thisID = items[k].id;
}
Here , "thisID" will give you the selected item's ID on the View.