Can we use jQuery in .vm ?
if yes, how ??
Did you put it in the "on document ready" function as Igor showed?
Using Jquery in vm file is bad. But you can use it like that:
<script type="text/javascript">
id = AJS.$("someselector").attr("id")
</script>
I wouldn't say it's "bad" as Alexy suggest, only a bit inconvenient - you can run into conflict between jQuery's $ and Velocity's $" In order to avoid problems, you need to assign $ to another variable:
<script>
(function(){
var q = AJS.$;
q('someselector');
})();
Of course if you have a large script, it's better extracted into a separate .js file and included on in the .vm via webResourceManager.
Thanks Alexy and Igor for your responses. I want to assign default value to description text field using javascript in vm file.
i tried jQuery("#description").text("Jira");
jQuery("#$description").text("Jira");
tried AJS.$("#description").text("Jira");
but not getting value in text field. Am i missing anythin ?
If #description is an input or textarea, you need to use val(), not text().
i tried that also. no change
"on document ready" function ???
I will try to explain in a more detailed way.
You need to add this code in your script:
AJS.toInit(function (){
AJS.$("#description").text("JIRA") //or AJS.$("#description").val("JIRA") - if it input field
});
if this not help, then you can provide more info about a vm file, and we will try to help you
ie a block like this:
(function(){ ...})();
Meaning, run the code in the block when the page is fully parsed and the DOM is available.
It looks like you're new here. Sign in or register to get started.