I'm not sure this is possible to do completely. It may not be meaningful in a lot of cases either. In your example, jobs.telegraph.co.uk is clearly part of the The Telegraph, which lives at telegraph.co.uk, but in other cases you have subdomains which have no relationship to the second level hostname, as is commonly found with free web hosting providers.
There are even "pseudo-NICs" such as CentralNIC which mess up the system by registering subdomains beneath domains such as uk.com, in which case there is clearly no relationship. See for example avon.uk.com.
Even if you ignore those, there are whole TLDs where the structure is a mess - .uk is one example. There are valid hostnames at the second level such as nhs.uk and mod.uk, most domains are registed at the third level such as bbc.co.uk, but .sch.uk domains can only be registered at the fourth level (i.e in the address http://learning.oriel.w-sussex.sch.uk/ you'd be looking for oriel.w-sussex.sch.uk and w-sussex.sch.uk cannot be a valid hostname)
I'm not sure if this can be done in javascript, but one possibility would be to do whois lookups at each level (i.e. jobs.telegraph.co.uk, telegraph.co.uk, .co.uk) until you get an error message along the lines of "registrations not available at this level", then accept the level below as the hostname. Unfortunately I think these messages vary by registrar, but at least there are less registrars than possible hostname permutations.