Hi :) I'm using jQuery Autosize plugin to resize some of my textarea elements dynamically. Everything is good but the problem is that when I add some textarea elements to the DOM dynamically, the autosize thing no longer works.
I initialize the plugin like so:
$(document).ready(function () {
$('textarea').autosize();
});
I tried to enable the plugin for my dynamically added textareas like:
myDynamicallyAddedTextarea.autosize();
Unfortunately, nothing happened. Can anybody help me with this?
sorry I can't comment yet, where are you adding this textarea at? can you post some of the code around the dynamic generation so that I can see when this stuff is getting called?
according to the docs, all you have to do is something like this for dynamically added elements...
function addTextArea() {
$(body).append($('<textarea class="test" />'));
$('.test').autosize();
});
//somewhere in code, but must be after the autosize plugin js has loaded
addTextArea();
Related
My website using Wordpress. When i viewsourge my Homepage (static page), it have code in tag:
text
Code is not have class or id, so i do not know how to remove it by JS or Jquery
How can i remove it by using JS or Jquery.
I really thank for your help
$('a').remove(); //if you use this, it'll remove all a from page.
$('parentdiv a').remove(); //remove the a from that parent div
It is working fine with jquery remove(),
$('a[href="https://tienichaz.com/danh-muc/do-tien-ich-du-lich/balo-du-lich"]').remove();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
text
google
You can depend on the [href] attribute of the (a) element to remove a specific (a) element
with this jquery code:
$("a[href='the-href-value-of-the-element-you-want-to-remove']").remove();
I have a big doubt. In a MVC project, I render a HTML template (loaded from .html file) into a View with MvcHtmlString.Create();
This works fine but have a problem. This HTML template need to do javascript functionality, the problem? That this don't work, because the HTML is rendered after the javascript and the js functionality not work.
Something like this:
<script type="text/javascript">
$(document).ready(function(){
$("#SomeID").click(funciton(){
//This don't work because the #SomeID not exists yet
});
});
</script>
<br />
#MvcHtmlString.Create(#Model.HTMLTemplateContent);
Someone can help me about this or tell me something at respect?
Thanks
Use jquery on method.
$(document).ready(function(){
$(document).on("click","#SomeID",function(){
alert("Working");
});
});
on method will work for current and future (Any thing injected to DOM later (Ex : through javascript code, ajax) elements.
Thanks! I not have idea about this.
Is possible to access at elements by the same "method"? How to do to get this? i.e
I'm using jSignature to implement sign en the document.
whit this:
$("#someDivID").jSignature();
I'm using now to access at div element with this:
var signCanvasOn = document.getElementById("someID");
signCanvasOn.jSignature();
signCanvasOn.jSignature("reset");
But this don't work for me, only work if I use:
$("#someID").jSignature();
$("#someID").jSignature("reset");
What is the real problem?
Have you tried adding the jquery at document level?
That's how i usually ensure that jquery continues to work with any stuff i load on the page dynamically.
Something like this:
$(document).on("click","#SomeID",function()
{
//This don't work because the #SomeID not exists yet
});
I'm trying to add text to a textarea on a form using jQuery. The form loads via JS from an external site.
Fiddle Here
The textarea is the 'When would you like a demo?' field. I believe it is this field.
<textarea name="Demo" class="k_textarea k_required" id="Question_1"/>
I've tried referencing the field directly by ID (see fiddle) and used a delay in case this was a resource loading order issue. Suggestions?
Use $(document).ready event instead of window.load.
jsFiddle Demo
$(document).ready(function(){
var input = $( '#Question_1');
input.val( input.val() + "Contribution to a certain fund");
});
Fiddle already does a window.onload if I recall correctly, that's why your example isn't working.
Change it to a jQuerys dom ready callback.
Btw, since Javascript is synchronous, loading order issue isn't a problem (as long as you don't introduce ajax ofc).
I have created a div using jquery and put some text in it:
var newdiv=$('<div id="content">').append('some text here');
$("#wrapper").append(newdiv);
Now I am trying to use the plugin masonry on the div.
I have added the following just below the above that creates the div:
$("#wrapper").masonry();
I have checked and jquery and masonry are loading correctly.
The new div called content shows in firebug correctly, but the masonry part is not doing anything to the new "content" div.
Any ideas?
Perhaps you should try adding 'appended':
var newdiv=$('<div id="content">').append('some text here');
$("#wrapper").append(newdiv);
$("#wrapper").masonry('appended', newdiv);
There's an append/prepend example here http://masonry.desandro.com/demos/adding-items.html
I tried some plugins but they all come with their own styling which takes quite some time to get rid of. Is there any plugin with minimal styling (or a really simple way) to apply custom background to select element? I just need something very simple.
Thanks
I found this one. It even degrades automatically if JavaScript is disabled.
http://ryanfait.com/resources/custom-checkboxes-and-radio-buttons/
With jQuery am using lines like this in my dom ready function :
$(".overlay").css("top","300px");
Goes like this in the header:
<script type="text/javascript">
jQuery(document).ready(function(){
$(".overlay").css("backgroundColor": "#0f0");
});
</script>
.overlay is the class of the div i wanna change and then comes the css property and its value.
Hope this helps.