How can I grab a text from a href in a website (page source) using javaScript?

Or link me to it! – msheshtawy Jan 15 '10 at 1:21 I was thinking something along the lines of what andybaird posted. But you may need to be more specific in the selector.

– brian Jan 15 '10 at 1:42.

In jQuery: var matches = $('a'). Attr('href'). Match(/crsEdId=(\d+)/).

Jetpack outputs $("a"). Attr("href") is undefined – msheshtawy Jan 15 '10 at 1:36.

If you've got the document in the current tab, I believe Jetpack gives it to you like: var doc= jetpack.tabs.focused. ContentDocument; Then in plain JS, get hold of the link by whatever means is most appropriate. For example to get the first link from the second list item: var menu= doc.

GetElementById('courses_menu'); var link= menu. GetElementsByTagName('li')1. GetElementsByTagName('a')0; If you are using Jetpack you can presumably rely on a new enough version of Firefox to have native support for the Selectors-API, so you could get this more easily without the use of an additional library such as jQuery, eg. : var link= doc.

QuerySelector('#courses_menu>ul>li:nth-child(2) a'); Now old-school DOM Level 0 gives you several easy properties to get the parts of a URL inside a link without having to resort to unreliable regex processing. If you want the whole query string crsEdId=78, you can say: var query= link.search. Substring(1); (the substring is to take off any leading?

Character. ) If there might be more query parameters and you want to specifically find the one called crsEdId you'd have to process the query fully, eg. : var crsEdId= getParameter(query, 'crsEdId'); function getParameter(query, name) { var pars= query. Split(/&;/g); for (var i= pars.

Length; i-->0;) { var n= parsi. Split('=')0; if (decodeURIComponent(n)===name) return decodeURIComponent(parsi. Substring(n.

Length+1)); } }.

It is Giving me null! Here is the website iam tryin to work on met.guc.edu. Eg and thats the code iam trying to do var doc= jetpack.tabs.focused.

ContentDocument; var link= doc. QuerySelector('#courses_menu>ul>li>li:nth-child(2) a'); jetpack.statusBar. Append({ html: "Boom!", width: 45, onReady: function(widget){ $(widget).

Click(function(){ jetpack.notifications. Show( " "+link+" " ); }); } }); – msheshtawy Jan 15 '10 at 2:07 There seems to be a spurious extra >li in that selector. – bobince Jan 15 '10 at 2:08 yeah , I was just trying something - .. well with and without it , its still giving me null – msheshtawy Jan 15 '10 at 2:13 Where exactly are you getting the null?

Is link null? Can you get #courses_menu on its own? Which part is failing here?

– bobince Jan 15 '10 at 9:21 The link is giving me null , iam printing the link , I will try to debug it , ( am kinda new in JS ) – msheshtawy Jan 15 '10 at 13:59.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions