(a)
Except as otherwise provided in Section 396a, if an action or proceeding is commenced in a court having jurisdiction of the subject matter thereof, other than the court designated as the proper court for the trial thereof, under this title, the action may, notwithstanding, be tried in the court where commenced, unless the defendant, at the time he or she answers, demurs, or moves to strike, or, at his or her option, without answering, demurring, or moving to strike and within the time otherwise allowed to respond to the complaint, files with the clerk, a notice of motion for an order transferring the action or proceeding to the proper court, together with proof of service, upon the adverse party, of a copy of those papers. Upon the hearing of the motion the court shall, if it appears that the action or proceeding was not commenced in the proper court, order the action or proceeding transferred to the proper court.
(b)
In its discretion, the court may order the payment to the prevailing party of reasonable expenses and attorney’s fees incurred in making or resisting the motion to transfer whether or not that party is otherwise entitled to recover his or her costs of action. In determining whether that order for expenses and fees shall be made, the court shall take into consideration (1) whether an offer to stipulate to change of venue was reasonably made and rejected, and (2) whether the motion or selection of venue was made in good faith given the facts and law the party making the motion or selecting the venue knew or should have known. As between the party and his or her attorney, those expenses and fees shall be the personal liability of the attorney not chargeable to the party. Sanctions shall not be imposed pursuant to this subdivision except on notice contained in a party’s papers, or on the court’s own noticed motion, and after opportunity to be heard.
(c)
The court in a proceeding for dissolution of marriage or legal separation or under the Uniform Parentage Act (Part 3 (commencing with Section 7600) of Division 12 of the Family Code) may, prior to the determination of the motion to transfer, consider and determine motions for allowance of temporary spousal support, support of children, and counsel fees and costs, and motions to determine custody of and visitation with children, and may make all necessary and proper orders in connection therewith.
(d)
In any case, if an answer is filed, the court may consider opposition to the motion to transfer, if any, and may retain the action in the county where commenced if it appears that the convenience of the witnesses or the ends of justice will thereby be promoted.
(e)
If the motion to transfer is denied, the court shall allow the defendant time to move to strike, demur, or otherwise plead if the defendant has not previously filed a response.