0

I have the following html:

<div type="Text with spaces" eventid="57" class="movie">...</div>

How can I read the type attribute with jQuery?

I tried this:

var type = $(".movie").attr("type");

but type contains only Text.

UPDATE:
This is how I was using this variable:

 $("#publicationBlock").load("/Publication/EventSchedule?eventId=" + eventId + "&type=" + type

In the action, I get only Text.

3
  • 1
    Which version of jquery are you using? The above code works fine for me with jq 1.7.2 and 1.8.3 and even 1.6.4 Commented Jan 22, 2013 at 7:12
  • 1
    Can you check your source html to make sure that the double quotes are present around the value Commented Jan 22, 2013 at 7:24
  • I just had this problem. It is caused by not using quotes around value. Commented Sep 19, 2013 at 23:18

2 Answers 2

1

that should work.

var type=$(".movie").attr("type");
alert(type);

fiddle here..

see if u missing this.
1) make sure your code is inside ready function $(function(){..
2) check the jquery version.. latest is better

updated

<div type="Text_with_spaces" eventid="57" class="movie">...</div>

and explode with '_' in your EventSchedule function

Sign up to request clarification or add additional context in comments.

1 Comment

Hmm. It seems the problem in other side. Check update in question, please.
0

I don't see the problem here?

This example is exactly the same as your code, but it was able to display the entire attribute: http://jsfiddle.net/rFYpE/

var type = $(".movie").attr("type");
alert(type);

How are you using the variable type?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.