Elective law is a Law of Succession in which the strongest vassal inherits. This is determined by the same formula used for Consanguinity law, but relationship to the present ruler is not considered.
This is important to note: Any vassal or sub-vassal is eligible, whether they are of the present ruler's dynasty or not. This can cause the player to lose control of their country, if the heir is not of their dynasty. However, it can also be used to select the best candidate of your dynasty, regardless of their relation to the prior ruler.
Since strength of candidates is partly based on control of provinces and titles, the player can affect the inheritance law by granting more titles to their preferred heir.
Note that vassals who are ecclesiastical rulers (bishops and archbishops) are not eligible for election.
If you have no eligible vassal rulers, heirs are chosen from amongst your court.