Tom Knowlton
asked on
timing of when the jquery runs
I have some jquery that runs on a page.
I also have a div that I am setting the inner HTML for on the page load.
The jquery uses the text inside this div to make a decision.
But, the jquery runs before the text gets set, so it is not able to do what is intended.
Is there a way to ensure the jquery runs after the div inner HTML is set?
I also have a div that I am setting the inner HTML for on the page load.
The jquery uses the text inside this div to make a decision.
But, the jquery runs before the text gets set, so it is not able to do what is intended.
Is there a way to ensure the jquery runs after the div inner HTML is set?
ASKER
That's the thing...right now it is inside the .ready() function...and it is not working right.
Here is where I am assigning the values in PageLoad on the server side with ASP.NET / C#:
Here is where I am assigning the values in PageLoad on the server side with ASP.NET / C#:
protected void Page_Load(object sender, EventArgs e)
{
bool showonlyinstorepickup = IWEBConfigAdmin.AllowInStorePickupOnly;
string instorepickupdescription = IWEBConfigAdmin.InStorePickupDescription;
if (showonlyinstorepickup)
{
showinstorediv.InnerHtml = instorepickupdescription;
}
else
{
showinstorediv.InnerHtml = "false";
}
////////////// THEN I WANT THE JQUERY TO RUN
ASKER
I even tried taking the jQuery code and putting it in a <script> block at the bottom of the master page, just above the ending </body> tag ----- and it made no difference.
Putting it in page_load does not put it in a jquery .ready() block. If you don't want to change this code, then you will need to put the jquery code in a function and call that function from the page load.
Add below tag in <head></head> tag
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></s cript>
i.e
Above code will alert the message containing text within div
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></s
i.e
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script>
$(document).ready(function(){
alert($("#showinstorediv").html());
});
</script>
</head>
Above code will alert the message containing text within div
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
What do you think about this possible interim solution?
This code:
-ensures we're on the page where we want the jquery applied
-calls a web method to find-out from the server what the "mode" will be for displaying the table
-by convention, anything other than the value "false" results in the jQuery being applied
I've tried this out and it seems to work okay.
But -- is this a hokey way to handle this?
var loc = window.location.href;
if (loc.indexOf("checkoutlegacy") != -1)
{
$.ajax({
type: "POST",
url: "WebGlobalMethods.asmx/SetToInStorePickupOnly",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg)
{
if (msg.d != "false")
{
$("tr:not(:has(th),:contains('" + msg.d + "'))", "table[id*='gvShipping']").hide();
}
},
error: LoadFailed
});
}
function LoadFailed()
{
}
This code:
-ensures we're on the page where we want the jquery applied
-calls a web method to find-out from the server what the "mode" will be for displaying the table
-by convention, anything other than the value "false" results in the jQuery being applied
I've tried this out and it seems to work okay.
But -- is this a hokey way to handle this?
Seems fine from a javascript perspective. That selector seems a bit complicated, but if it's working, I don't think it's horrible.
MacAnthony- If u could famillar with U never told this tat page_load will be called after ready fun
ASKER
I think this solution also would have worked, or was on the right track.
The other option would be to run the jquery function inside the body onload, but I like the first option more.