javascript - event to associate with div -
i have mvc application in getting results webservice , assigning model property. want pass result in javascript function , display alerts. have code in javascript can't find particular event associate div when page displays, should trigger alert (i have tried div onload). reason can't attach page or other thing except div that, it's partial view div's being loaded/unloaded on click of every menu item. need help.
javascript
myobject.showverificationstatus = function (verificationstatus) { alert("status: " + verificationstatus); };
view code
@if (model.hasanyvalue) { var verstatus = model.clientverificationstatus != null ? ((verificationstatuss)model.clientverificationstatus).tostring().toupper() : null; <div id="divverificationstatus" class="divdetail_sectiontitle" onload="object.myobject.showverificationstatus(@verstatus)"></div> }
just use document.ready
on page. remove onload
div
. add verstatus
data-*
attribute. consider below example:
your viewcode :
@if (model.hasanyvalue) { var verstatus = model.clientverificationstatus != null ? ((verificationstatuss)model.clientverificationstatus).tostring().toupper() : null; <div id="divverificationstatus" class="divdetail_sectiontitle" data-status="@verstatus"></div> <!--^^^add this--> }
now on document.ready fetch data-status
, alert
it.
$(document).ready(function(){ alert("status - " + $("#divverificationstatus").data('status'); });