0

Below is the div that I want to alter

<div id="@page.Page" class="pageMessages" data-messages='@Html.Raw(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(@page.Messages))'></div> 

I want to change the value of the message when a javascipt function is called from an external .js file. What is the correct way to do this?

2 Answers 2

1

Like So...

// This Performs the Change
$('#changeme').attr('data-messages', 'New Value');

// Show the Change
$('#changeme').html( $('#changeme').attr('data-messages') );

Here is a Working Fiddle

The one problem I see is the id='@page.Page' , this doesnt work.

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

Comments

0

I hope i get what you're trying to do, you can use jquery's change attribute for that

JQUERY

<script>
$(document).ready(function(){
   $(".pageMessages").attr("data-messages","your-new-value-here");
});
</script>

DOC: http://api.jquery.com/attr/

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.