I have a variable "widgetDataHash" (string) and script tag like this:
<script
type="text/javascript"
id="widget"
data-hash="{{widgetDataHash}}"
src="www.widgetsrc.com">
</script>
I want to insert value of widgetDataHash to data-hash attribute like that. But when it run, it just show a normal text {{widgetDataHash}} instead of value of widgetDataHash.
Any solution for this ?
I think you should write like this [attr.data-hash]="widgetDataHash" for angular 2+ and for Angularjs you should write like this
ng-attr-data-hash="widgetDataHash"
I should mention that I found this solution (for Angularjs solution) in a link Nobita answered that. For more information check Conditionally adding data-attribute in Angular directive template answers
Related
I am trying to figure out how to write jQuery code to insert meta data in to an element, specifically this: data-section-name="home"
I want to insert this in a div with an ID of home-section and the output would be like this:
<div id="home-section" data-section-name="home">
(some code here...)
</div>
I am using a divi builder in Wordpress
If you need the data attribute to appear in the HTML source use attr():
$('#home-section').attr('data-section-name', 'home');
If the data attribute is going to be read by a jQuery library then you can use the data() method instead, which is more performant:
$('#home-section').data('section-name', 'home');
The caveat in both cases is to ensure that you execute this line of code before whatever library depends on that data attribute being present.
<body ng-init="user=${userID};month=${month};curPageNum=${currentPage}">
I wrote this by JSP,and i initial the value in the body tag,
but in the controller,i wrote:
console.debug($scope.user + " "+$scope.month}
but only $scope.month have the value,$scope.user displays undefined,
and after some tries, i found that if the value contains letters,it just display undefine,only the pure number can work.
I don't know why this happen,so can you help me to solve this?Thank you very much
Because your initialisation of the variables does not wrap the values in strings they are failing to assign. the JS is reading it as user=mary; i.e. assign the variable mary to user. That's why numbers work. Try this :
<body ng-init="user='${userID}';month=${month};curPageNum=${currentPage}">
You can refer Dynamic ng-init variable - Angularjs
Also, You can refer http://www.w3schools.com/angular/angular_directives.asp
you can initialise value as below
<body ng-init="user='${userID}';month='${month}';curPageNum='${currentPage}'">
On a website that I am maintaining, I have many code lines like the following one:
<strong>doi</strong>
reference
where "website" is an actual website address and "reference" is a number which depends on each entry of this type (while the website address is always the same). In html/ccs; is it possible to create a command, let's call it doi such that instead of always writing the two lines above, I would equivalently write
<doi>reference</doi>
No it's not possible using just html/css, but it is possible using javascript/jquery or a javascript framework, like angularjs.
Here's an example using jquery:
https://jsfiddle.net/partypete25/31dzyjgL/
<!-- HTML -->
<doi>121</doi>
<!-- JavaScript -->
$("doi").each(function(){
var ref = $(this).text();
$(this).replaceWith( "<strong>doi</strong><a href='http://website/"+ref+"/' target='_blank'>reference</a>" );
});
So the script will look for all of your custom "doi" tags, and replace them with the fleshed out label+link with the dynamic reference.
Is there a way to add attributes to script tag using registerJs?
For example:
$this->registerJs("var options ={'a' : 2};", View::POS_END, 'my-options');
The above will output something like that:
<script type="text/javascript">var options ={'a' : 2};</script>
But I need to add some attributes to script tag(or even change the type for richsnippets)
I have 6 different links,and each link is going to call a different Ajax function.
I'm using the <a href> tag because I want it to appear as a link....Can I use this tag to call the Ajax function? or it only works with URL links?
THANKS!
This is how I call mine. I give my elements a class name such as 'clickable' then use Jquery's click function as so.
$('.clickable').click(function() {
//do ajax
});
Then in the function, I get the id of the element as so. var id = this.id, this will get the unique id of the element.
After that I use the $.post method of Jquery, the shorthand version of ajax and complete whatever call you need to make when the user clicks that link using the id.
Of course, in my case I never use the anchor tag, I just make is a button or apply the . click to the element I wish to add the ajax call to, but you could just surround the "link" in a span or a div to simulate the same effect.
Hope this helps in some way or another.
Text
or even as they wrote, with jquery
Text
<script type="text/javascript">
$(document).load(function(){
$('#blabla').click(function(){
alert("Clicked");
});
});
</script>
Yes you can incorpore the link in the following way:
- on your link you can write ...
Here you can see further information about this topic:
What is the difference between the different methods of putting JavaScript code in an ?
You can extract the value of the href attribute and use it for your AJAX call...
(it is actually the proposed way to handle it..)
yes you can, if any client side script functions (javascript or jquery) applied than it will execute first.