tags:

views:

47

answers:

3

Hello,

I have about 400 links, ie., http:// in a div. I want to filter only the links ( http:// )

$("a[href$='']").each(function() {
        $(this).append('#only_http').attr('href');
    });

Thanks Jean

+5  A: 
$("a[href^='http://']").each(function() {
    $(this).append('#only_http').attr('href');
});

This will select all elements that contain the text 'http://':

$(":contains('http://')")

If beyond that you're interested in finding the actual text within the element, match it with a Regex like this:

$(this).text().match(/http:\/\/\S+/) // very simple, probably not too reliable

I don't know what you want to do with this afterwards...

deceze
............Why the ^?
Jean
`^=` means "beginning with"
Tatu Ulmanen
Does not work....
Jean
@Jean What doesn't work? Did you debug it? Did it select all the elements you want?
deceze
@tatu does not select anything, just gives me a blank page. -For ease, I have hidden the div that contains the text+links.
Jean
@Jean Do you have any links that start with "http://" on your page? This must be written in the source code, relative links won't work. Because this selector *does* work.
deceze
there are links beginning with only http:// but not <a href="http://">like http://www.google.com not <a href="http://">Google</a>
Jean
@Jean Are you saying that what you're trying to find is **raw text** that may look like `http://google.com`, not "real" links? Do you want to find that *anywhere* in the page, or just within certain text blocks?
deceze
@tatu Yes its raw text, and any where in the page
Jean
@Jean See update.
deceze
@tatu it does work, I put an alert(), now I have to find a way to "each" it :)
Jean
@Jean, note that you're not talking with me, but with deceze :)
Tatu Ulmanen
@deceze it does work, I put an alert(), now I have to find a way to "each" it :)
Jean
A: 

........

$('a[href^="http://"]')..............more code
Sarfraz
That's all, it filters all the links from the page, and displays
Jean
A: 

so,the answers you received by now are good, meaning they told you how to select what you want. and that fact that you say it is not working amazes me, but still

here you are a proof that it actually works. (just hit Run)

http://jsfiddle.net/4Pzya/link text

and then copy paste what you need although i think you could have done it yourself

undertakeror
Please read through all the comments and re-read the question. Thanks
Jean
well,i read it and the comments still don't understand that is different in you Q from all the answer you got and/or why can't you filter the good stuff and do the rest yourself. or you could edit/commnet you Q and make it more understandable
undertakeror