c# - getelementbyid().length undefined? -



c# - getelementbyid().length undefined? -

i have code in c#:

@foreach (var photo in photos){ <div class="comment1" id="many"> @photo.name </div> } <input type="button" name="button" onclick="count()" />

and want know how many "photo.names's" there are, made javascript

function count(){ var algo = document.getelementbyid("many"); alert(algo.length); }

but unusual reason gives me "undefined". why happening? i have javascript on separate file

why happening?

html elements not have length property. if you're looking length of element contains you'd need this

document.getelementbyid("many").innerhtml.length;

keep in mind ids should unique element.

if you're looking "how many" comments there are, you'd need following

document.getelementsbyclassname("comment1").length;

classes don't need unique across elements , and element can have more 1 class.

c# javascript

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -