link-tag

RegEx to return 'href' attribute of 'link' tags only?

大兔子大兔子 提交于 2019-11-28 12:44:49
Im trying to craft a regex that only returns <link> tag hrefs Why does this regex return all hrefs including <a hrefs? (?<=<link\s+.*?)href\s*=\s*[\'\"][^\'\"]+ <link rel="stylesheet" rev="stylesheet" href="idlecore-tidied.css?T_2_5_0_228" media="screen"> <a href="anotherurl">Slash Boxes</a> thank you Either /(?<=<link\b[^<>]*?)\bhref=\s*=\s*(?:"[^"]*"|'[^']'|\S+)/ or /<link\b[^<>]*?\b(href=\s*=\s*(?:"[^"]*"|'[^']'|\S+))/ The main difference is [^<>]*? instead of .*? . This is because you don't want it to continue the search into other tags. Avoid lookbehind for such simple case, just match

Changing the href of a link tag using javascript

随声附和 提交于 2019-11-28 01:35:32
Hi I am trying to change the href of a link tag so that when a button is pressed a new style sheet is loaded. This is what I have so far- function addcss() { var findlink = document.getElementsByTagName("link"); findlink.href = "stylesheetxhtml.css"; } Any Help Much appreciated Thanks You can't set the href directly like that, because document.getElementsByTagName returns all the <link> tags (as a NodeList ). If you're positive you only have one, use this: var findlink = document.getElementsByTagName("link"); findlink[0].href = "stylesheetxhtml.css"; If you have multiple <link> elements and

Get contents of link tag with javascript - not CSS

一曲冷凌霜 提交于 2019-11-27 20:19:19
Assuming I have <LINK rel="Index" href="index.html"> <LINK rel="Next" href="Chapter3.html"> <LINK rel="Prev" href="Chapter1.html"> (taken from w3 web site sample) Does anyone know if these are accessible through the JavaScript DOM? I want to know If I have link tags like this in the HTML document whether they are read like the main document and added to the DOM and if I can access their DOMs as well. I have this code: <script type="text/javascript"> var your_url = 'http://www.example.com'; </script> <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js

RegEx to return 'href' attribute of 'link' tags only?

有些话、适合烂在心里 提交于 2019-11-27 07:16:10
问题 Im trying to craft a regex that only returns <link> tag hrefs Why does this regex return all hrefs including <a hrefs? (?<=<link\s+.*?)href\s*=\s*[\'\"][^\'\"]+ <link rel="stylesheet" rev="stylesheet" href="idlecore-tidied.css?T_2_5_0_228" media="screen"> <a href="anotherurl">Slash Boxes</a> thank you 回答1: Either /(?<=<link\b[^<>]*?)\bhref=\s*=\s*(?:"[^"]*"|'[^']'|\S+)/ or /<link\b[^<>]*?\b(href=\s*=\s*(?:"[^"]*"|'[^']'|\S+))/ The main difference is [^<>]*? instead of .*? . This is because

Use jsoup to parse XML - prevent jsoup from “cleaning” <link> tags

[亡魂溺海] 提交于 2019-11-27 05:43:14
问题 In most case, I have no problem with using jsoup to parse XML. However, if there are <link> tags in the XML document, jsoup will change <link>some text here</link> to <link />some text here . This makes it impossible to extract text inside the <link> tag using CSS selector. So how to prevent jsoup from "cleaning" <link> tags? 回答1: In jsoup 1.6.2 I have added an XML parser mode, which parses the input as-is, without applying the HTML5 parse rules (contents of element, document structure, etc).

Get contents of link tag with javascript - not CSS

不羁岁月 提交于 2019-11-26 20:23:16
问题 Assuming I have <LINK rel="Index" href="index.html"> <LINK rel="Next" href="Chapter3.html"> <LINK rel="Prev" href="Chapter1.html"> (taken from w3 web site sample) Does anyone know if these are accessible through the JavaScript DOM? I want to know If I have link tags like this in the HTML document whether they are read like the main document and added to the DOM and if I can access their DOMs as well. 回答1: I have this code: <script type="text/javascript"> var your_url = 'http://www.example.com