Reputation: 1520
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
.
Upvotes: 0
Views: 2203
Reputation: 36541
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
Upvotes: 1
Reputation: 79073
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?
Upvotes: 0