How would I select this input using Javascript selectors? - javascript

I am not sure how to select the input below using Javascript selectors. I tried this but that doesn't seem to be correct:
$("input:text[name=[11235]");
<div class="Row-LineDetail A" id="Row1235">
<span class="Col-Label LineIndent1">
</span>
<span class="Col-Dollar">
<input type="text" name="l1235" value="$5,000.00" cols="8" onkeyup="validateNegAmount(this);" onblur="transform(this)" onfocus="removeFormatters(this);this.select();">
</span>
</div>

$('input[name="l1235"]')
That would work if you are using jQuery, as in your example above.

You'll want something like this:
$("input[name='11235']");
Take a look at http://api.jquery.com/category/selectors/attribute-selectors/ for more information about attribute selectors.

Since you appear to be using jQuery the following would work:
$("input[name='l1235']")

with using jquery
$('input[name="l1235"]')
with pure javascript
document.getElementsByName('l1235')

For you
Simply use
$('input[name=l1235]');
Other method
If you want to select the text elements, then you can ues
$('input[type=text]');
Other queries can be executed after this such as:
if($(this).attr('name') == 'l1235') {
And so on! :)

Related

Can I use html5 data attribute in HTML select box element?

Any idea can I use .data attribute in HTML select box?I red HTML5 documents but I didn't find any information that could help me.
Is it legal:
<span>Select depatament</span>
<span>
<select id="department" onchange="EnableSelectBox(this)" data-spacing="10cm">
<option selected disabled>-Select-</option>
</select>
</span>
Yes it fine to use data in Html5 tag. I don't know why you want to use in such a way, but you can use it.
for example like this
$(document).ready(function() {
alert($('#department').data('spacing'));
});
jsfiddle link
Using data attributes
Any attribute on any element whose attribute name starts with data- is a data attribute.
To answer the question: Yes. You can use data attributes on any element.
It works fine. Test in JS using:
alert(document.getElementById("department").getAttribute("data-spacing"))

Changing text after a <br> with jquery

I have a span tag like this and stored in the variable "foo"
<span class="right margin">
سی ئی 1500
<br>
Nicole Kidman
</span>
Using jQuery OR javascript, how can I change the "Nicole Kidman" clause with something I want? innerHTML changes everything in the <span>
Edit: I edited the text with this code foo[0].lastChild.nodeValue="something else"; but is there another way doing that using only jQuery?
I recommend you add another span tag around Nicole Kidman.
<span class="right margin">
سی ئی 1500
<br>
<span>Nicole Kidman</span>
</span>
and change the text like this:
$(".right").find("span").text("something you want");
<span> is an inline element. We avoid using <br/> in them.
It is also advisable to use another tag to encapsulate your 'Nicole Kidman' text.(Like another <span>)
I'm not aware of your entire HTML structure so I'm going with what you have posted. Here is a fiddle example for how it can be done.
Here the foo is not a jQuery object:
foo.lastChild.textContent='something you want'
So the foo is a jQuery object, but you still need to access the dom element directly:
foo.contents().eq(-1).textContent='something you want'

javascript change div html when click span

Ok I have a small question.
I have the following
<div><span class="spanright" onclick"">Update</span><label class="myinfo"><b>Business information:</b></label></div>
What I want to do is when the user clicks on the span it changes the html after the label an adds an input box and submit button.
I think I need to do a this.document but not sure
Hi hope this might give you a small understanding of what to do when it comes to registering events. StackOverflow is about you learning how to do something, so we dont write the scripts for you, we are just trying to point you in the right direction of it.
http://jsfiddle.net/WKWFZ/2/
I would recommend you to import jQuery library, as done in the example, if possible. It makes the the world of javascript alot easier!
Documentation to look up:
http://api.jquery.com/insertAfter/
http://api.jquery.com/bind/
Look up some jQuery tutorials! there is alot of them out there.
I added a form which will hold the input
JavaScript:
function showInput()
{
document.getElementById('container').innerHTML += '<input type="text"/><input type="submit"/>';
}
HTML:
<div id="container">
<span class="spanright" onclick"showInput()">Update</span>
<label class="myinfo"><b>Business information:</b></label>
</div>
Summoner's answer is right, but I prefer using jquery (it's loaded on almost every page I work with):
HTML:
<div id="container">
<span class="spanright">Update</span>
<label class="container"><b>Business information:</b></label>
</div>​
Javascript:
​$(".spanright").click(function(){
$("#container").append('<br /><input type="text"/><input type="submit"/>');
$(".spanright").unbind('click');
})​​;​
This way, the click event will work once, as it is what you probably intended.
Try this in jquery flavor --
$(document).ready(function(){
$(".spanright").click(function(){
$(".myinfo").css("color","red");
});
});
Check fiddle --
http://jsfiddle.net/swapnesh/yHRND/

Jquery change value of span tag - reference from another div

So my html code is:
<div class="product-details">
<div class="availability in-stock">
Availability: <span>In stock</span>
</div>
</div>
I would like to use Jquery to change the span value of "in stock". I am somewhat new to Javascript and Jquery, so how would I change that span value without it having an id to reference.
Many thanks in advance!
$('.in-stock span').html("your new string");
http://jsfiddle.net/hQqtU/
$('.product-details .availability span').text('foo');
Fiddle: http://jsfiddle.net/maniator/EryVF/
What you are looking for is either the text() or the html() like so:
$('.availability span').html('This is what you want to change it to');
Here is an example: JsFiddle Demo

the selector in JavaScript

I want to get the object of this code ,
<input class="radio"
id="conversation_sub_kind_id_208"
name="conversation[sub_kind_id]"
onclick="set_department_name('department_name208')"
type="radio"
value="208" />
I want to use jQuery Framework to get the object, like the document.getElementbyTagName("conv..."); what should i do in here?
Thank you, and best regards!
$('#conversation_sub_kind_id_208');
more here
It should be as simple as $('#conversation_sub_kind_id_208'). That would give you the jQuery object. If you want the underlying DOM element, do it like this: $('#conversation_sub_kind_id_208').get(0).
Or you could not use Jquery and simply do:
document.getElementById("conversation_sub_kind_id_208");

Categories