Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Ok guys, let's suppose I have one html form with 2 fields like this:
<fieldset>
<p><label>Login<br><input type="text" class="inpText" name="user" id="user"/> </label><span class="provider">#isp.com</span></p>
<p><label>Password<br><input type="password" class="inpText inpPass" name="pass" id="pass"/></label></p>
</fieldset>
Now, I need to replace the entire code inside the < fieldset > - < /fieldset>.
Remove both inputs, or add how many inputs I need, or just write one < p > inside the < fieldset>, or whatever, I just need to replace the code between 2 'flags'; in this case the fieldset. How to do that using javascript? JQuery is acceptable too, but I prefer javascript only if possible.
Thank you.
give the fieldset an id and do $('#fieldset_id').html('html to replace with');, or with plain js use document.getElementById('fieldset_id').innerHTML = 'html to replace with';
Well if jQuery is acceptable:
$("fieldset").html("NEW HTML HERE");
Give your fieldset an id and then use document.getElementById("fieldSetId") to get the fieldset. You can then alter it with innerHTML property.
Here is a demo http://jsfiddle.net/thefourtheye/vF7Xb/
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
With
input[name="abc"]
but what if the name contains stuff like [ and ] ?
My input looks like:
<input type="text" name="abc[def][5][xyz][]" value="" />
There is no need to escape [] if the attribute value is enclosed within ""
$('input[name="abc[def][5][xyz][]"]')
Demo link on: Fiddle
Use escape characters input[name=\[def\]\[5\]\[xyx\]\[\]].
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am trying to find out how to set the max value and min value of html5 type input by javascript or jquery.
<input type="number" max="???" min="???" step="0.5"/>
Would someone please guide
jQuery makes it easy to set any attributes for an element - just use the .attr() method:
$(document).ready(function() {
$("input").attr({
"max" : 10, // substitute your own
"min" : 2 // values (or variables) here
});
});
The document ready handler is not required if your script block appears after the element(s) you want to manipulate.
Using a selector of "input" will set the attributes for all inputs though, so really you should have some way to identify the input in question. If you gave it an id you could say:
$("#idHere").attr(...
...or with a class:
$(".classHere").attr(...
Try this:
<input type="number" max="???" min="???" step="0.5" id="myInput"/>
$("#myInput").attr({
"max" : 10,
"min" : 2
});
Note:This will set max and min value only to single input
Try this
$(function(){
$("input[type='number']").prop('min',1);
$("input[type='number']").prop('max',10);
});
Demo
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I would like to match this following condition using regex
<P ***anything here*** >
So essentially, I want to strip any opening P tag with any attributes. I dont want to stip anything else in the string.
Test case/
<p style='color: green;'>What a fine day it is</p>
Desired Result/
What a fine day it is</p>
As #kojiro already mentioned, this is not a good path, however:
var sample = "<p style='color:green;'>What a fine day it is</p>";
var result = sample.replace(/<p\b[^>]*>/ig,'');
// result = "What a fine day it is</p>"
Obligatory Footnote if you have an attribute that contains the > character within the <p> tag, this will fail epically. but, then again, that's why the above referenced post exists on SO. ;-)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I need to get the element by class of "balls" from the div gameContent.
Basically grabbing the lottery numbers from Play4 from this site:
http://www.flalottery.com/play4.do
How can I get the element by class from another class? If I just do balls, all of the numbers show up, which aren't relevant and would mess up data.
Do you mean something like this:
document.getElementsByClassName('gameContent')[0].getElementsByClassName('balls')
Get elements by class "gameContent" followed by "balls". Query assumes that the first gameContent is what we are interested in.
Hope this helps.
you can use the following query selector
var elems = document.querySelectorAll(".gameContent .balls")
That is pure JavaScript. You can of course use the same query selector for jQuery
For instance with jQuery this would be
var elems = $(".gameContent .balls")
Notice how the query selector is identical.
Did you try
$(".gameContent .balls")
Judgeing by the page you've included in your question, you'll probably want to iterate through the <span> elements to get each ball number:
$('.gameContent .balls').each(function(){
alert('next ball: '+$(this).html())
});
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to attach a listener to an element created via js dom manipulation. I thought that this is what jquery ON was for, but the below example is not working.
It works with the initial element, but not with any that are added via JS. The added elements have the correct class name.
<div id = "tag_options">
<div class = 'tag_option'>test</div>
</div>
function greet(event) { alert("Hello "); }
$("[class='tag_option']").on("click", {}, greet);
Try this:
function greet(event) { alert("Hello "); }
$("#tag_options").on("click", ".tag_option", greet);
Use delegation, e.g:
$(document.body).on("click","[class='tag_option']", greet);