using jquery for a button with a "." in the id [duplicate] - javascript

This question already has answers here:
How do I get jQuery to select elements with a . (period) in their ID?
(8 answers)
Closed 4 years ago.
Hi guys ive got a button with jquery like this :
<html>
<button id = "index.php">
</button>
</html>
<script>
$('#index.php');').click(function(){
//stuff
});
</script>
however it seems that the id with a "." isnt accepted by jquery - is there a way to make it work?

Try escaping the .
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id = "index.php">
</button>
<script>
$('#index\\.php').click(function(){
console.log('stuff');
});
</script>

Related

Can I make Javascript inside Javascript? [duplicate]

This question already has answers here:
Can scripts be inserted with innerHTML?
(26 answers)
script tag create with innerHTML of a div doesn't work
(3 answers)
Closed 3 years ago.
I will make javascript inside javascript like this code.
<p id="div"></p>
<p id="jancuk"></p>
<script>
document.getElementById("jancuk").innerHTML = '<script
src="encryption.js" type="text/javascript">' + '</script>';
</script>
<script>
document.getElementById("div").innerHTML = "text show"; </script>
Code can't work correctly.
I will include data javascript 1 to javascript 2. it's mean wrapper inside one html document.
Please help me if you know about this.

.on("click",...) not working on objects created with the same on click function [duplicate]

This question already has answers here:
Event binding on dynamically created elements?
(23 answers)
jQuery function not binding to newly added dom elements
(13 answers)
Closed 6 years ago.
since I am new to JS / jQuery it is probably a obvious problem (but no exception thrown). I read that I can't use .onclick so i tried this approach with .on("click"...)
I try to build a table that adds new lines under the clicked line. This should also work for the newly created lines.
My html:
<tbody>
<tr id="line1"><td>Stuff1</td><td>Stuff</td><td>Stuff</td><td>Stuff</td><td>Stuff</td></tr>
<tr id="line2"><td>Stuff2</td><td>Stuff</td><td>Stuff</td><td>Stuff</td><td>Stuff</td></tr>
<tr id="line3"><td>Stuff3</td><td>Stuff</td><td>Stuff</td><td>Stuff</td><td>Stuff</td></tr>
<tr id="line4"><td>Stuff4</td><td>Stuff</td><td>Stuff</td><td>Stuff</td><td>Stuff</td></tr>
</tbody>
My JS:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("tr").on("click",function(){
var childId = $(this).attr("id")+1;
if($("#"+childId).length){
$("#"+childId).toggle();
}else{
$(this).after('<tr id="'+childId+'"><td>Stuffxxxx</td><td>Stuff</td><td>Stuff</td><td>Stuff</td><td>Stuff</td></tr>');
//AJAX
}
});
});
</script>
Thanks for your help! :)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("table").on("click","tr", function(){
var childId = $(this).attr("id")+1;
if($("#"+childId).length){
$("#"+childId).toggle();
}else{
$(this).after('<tr id="'+childId+'"><td>Stuffxxxx</td><td>Stuff</td><td>Stuff</td><td>Stuff</td><td>Stuff</td></tr>');
//AJAX
}
});
});
</script>

Get custom property from a button using Javascript [duplicate]

This question already has an answer here:
Select option base on property key in value
(1 answer)
Closed 6 years ago.
I have this button in HTML , with a property defined by me on it (data-filter-params):
<button class="button" type="submit" data-filter-params="{'Type', 'Filter.Type'},{'Code','Filter.Code'}" >Filter</button>
How can I take with JavaScript\JQuery the value for data-filter-params
plain javascript
var btn = document.getElementsByClassName('button')[0];
console.log(btn.dataset.filterParams)
jQuery
console.log($('.button').data('filter-params'));
This should solve it
var value
$(function(){
value = $('button').attr('data-filter-params')
})
JSfiddle: https://jsfiddle.net/mayank_shubham/3k97gg9k/
It's very easy,
HTML:
<button id="btnSubmit" class="button" type="submit" data-filter-params="{'Type', 'Filter.Type'},{'Code','Filter.Code'}" >Filter</button>
jQuery:
var attr = $('#btnSubmit').attr('data-filter-params');
alert(attr)

C#: Using HTMLAgilityPack how to get a value inside a script tag [duplicate]

This question already has an answer here:
Parsing HTML to get script variable value
(1 answer)
Closed 7 years ago.
I am using HTMLAgilityPack. I want to get a value inside a script tag, see the code:
<div id="frmSeller" method="post" name="frmSeller">
<div class="clear"></div>
<script type="text/javascript" language="javascript">
Biz.Product.GroupItemSwitchLogic.init();
Biz.Product.GroupItemSwitcher.init({
properties:null,
availableMap:[{"info":{"item":"28-200- 286","price":95.99,"vehicle":null},"map":[]}],
selectedProperties:[]
});
</script>
</div>
From there I want to get value of "price" that is 95.99.
How can i get this kindly tell me, what type of Regex I can use....
Thankyou
You can do some string manipulation like this
s = the html code
var s = z.Split(new String[] { #"price"":" }, StringSplitOptions.None);
var price = s[1].Split(',')[0];
and now price variable has your price

javascript document.getelement not working [duplicate]

This question already has answers here:
Why does jQuery or a DOM method such as getElementById not find the element?
(6 answers)
Closed 8 years ago.
I am very new to javascript. I am trying to place value on one input field. But it is not working, I don't know why..
document.getElementById("c_add").value='sssssss';
in the text area with id "c_add", I supposed that value will place as "sssssss", but it is not setting any value..
Full Code:
<body>
<script type="text/javascript">
document.getElementById("c_add").value='sssssss';
</script>
<textarea name="c_add" id="c_add"></textarea>
</body>
Did you tried do like this?
<input type="text" id="mytext">
<script type="text/javascript">
var elem = document.getElementById("mytext");
elem.value = "My default value";
</script>

Categories

Resources