$(a,this).attr('href') returns undefined?

Seems like artefact has two a s. Based on this: $('. Artefact').

Click(function () { var storyId = $('a', this). Filter("href"). Attr('href'); console.

Log(storyId); }) EDIT On second thought, this looks cleaner: $('. Artefact'). Click(function () { var storyId = $(this).

Find("ahref"). Attr('href'); console. Log(storyId); }).

Seems like . Artefact has two as. Based on this: $('.

Artefact'). Click(function () { var storyId = $('a', this). Filter("href").

Attr('href'); console. Log(storyId); }); EDIT On second thought, this looks cleaner: $('. Artefact').

Click(function () { var storyId = $(this). Find("ahref"). Attr('href'); console.

Log(storyId); }).

I am retard.... FIXED. I didn't realise that A) The link I did have in, was infact within a different DIV that was also in artefact, but B) that the first link in the artefact div, has no HREF attribute. Im sorry for wasting time :( – nmyster Apr 11 at 11:09 @Neil: You're not creating a YouTube playlist, are you?

– Salman A Apr 11 at 11:19 No. I have a university coursework to make a web magazine type thing... i've decided to make a website that looks like a news paper, im using PHP and jquery to load the stories from a database... newspaper.nmyster.co. Uk if you wanna check it out.Im new to jquery.

– nmyster Apr 11 at 11:34 I meant AJAX and PHP, but using Jquery cause its better – nmyster Apr 11 at 11:34.

Is . Artefact a link? If yes, why to use $('a', this) instead of just $(this)?

1 . Artefact is a div, it has an image in it and a anchor tag. – nmyster Apr 11 at 10:48 using @Raynos comment on your question (the $(this).

Find('a') part) should work with that combination – Thor Jacobsen Apr 11 at 10:50 a, a 16 is returned when I use ("a", this)) in the console, so how would I get the 17 on its own, can I just create a variable with ("a",this) as the value, then cut the string the last three chatacters, then remove the – nmyster Apr 11 at 10:52 Hmm... look at this jsFiddle: jsfiddle. Net/5vPhK - is it your case? It works just right.

– Olegas Apr 11 at 10:53.

You have 2 links in the div element (Looking at code you provided). So to get the href (if that link is always the last one in div, you should use: $('. Artefact').

Click(function() { var storyId = $('a', this).last(). Attr('href'); console. Log(storyId); }); And as others have said, you were missing parentesis too.

Try this: var storyId = $(this). Attr('href').

I still get undefinded :( – nmyster Apr 11 at 10:54.

Neil Stewart: See -- jsfiddle.net/Chby2/ You didn't add the artefact class to the link and your jQuery code was also missing the closing parenthesis: ).

I tried the link, and it works... I tried to copy that into my script, and it does not... awww :(. I the artefact div, is held in a another div called story_preivew. And these are brought in using PHP when the page is loaded... would that have anything to do with the problem?

I know if you get data using ajax you need to use .live() but I didn't think that would be a problem in this case – nmyster Apr 11 at 11:00.

Yeah, closing parenthesis is in fault jsfiddle.net/h7HuJ/1/ I used your given HTML code. You have two anchors inside that DIV, so you need to specify, which one to select. I used your class name.

Related Questions