To begin, identify the specific link tag you want to modify with a new href attribute. In the provided example, I targeted the first link tag using .eq(0)
in jQuery and utilized .attr()
to adjust the href value.
Important Note:
If you do not specify an index, the attribute will be applied to all link tags within the head section.
var stylesheet = mobile ? 'mobile.css' : 'non-mobile.css';
$('link:eq(0)').attr('href', stylesheet)
If you need to target the second link tag, simply use .eq(1)
. Remember, this operates on an index basis.
$('link:eq(1)').attr('href', stylesheet)