Why attr id not assigned to form? [closed] - javascript

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 months ago.
Improve this question
Please advise why this code doesn't work. The ID of the form should appear in input field as value.
$("button").click(function() {
$("form").attr(id, "message");
$("input").val($("form").attr('id'));
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form>
<input type="text">
</form>
<button>Check</button>

You need to use quotes for the id
$("form").attr("id", "message");

Related

Can't write html dynamically in Jquery innerHtml [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I use jquery to put html dynamically but it is not working...
Here is what I have tried
$("#root").innerHtml("<h1>Hello</h1>")
You should not use innerHtml instead use html()
You can do as below
$("#root").html("<div>Hello</div>")

Why is my custom data attribute not working? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
Using jQuery
console.log($(this).html());
console.log($(this).data('section'));
yields
Include Children?
and
undefined
and I'm not sure what I'm doing incorrectly. The <a> here is inside an un-ordered list <li> tag, but I'm not sure why that should matter. Thanks in advance!
As you said it is <li> enclosing the <a>
then it should be:-
console.log($('li a').html());
console.log($('li a').data('section'));
Example:-
console.log($('li a').html());
console.log($('li a').data('section'));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li>Include Children?</li>
Note:- you can do $(this).find('a').data('section'); also based on your HTML structure.

JavaScript innerHTML change onclick not working [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I want to change a piece of text with the click of a button, this doesn't work. Any ideas?
<div>
This text should stay, <span id="x">This text should change.</span>
</div>
<button type="button" onclick='change()'>Change</button>
<script type="javascript/text">
function change() {
document.getElementById('x').innerHTML='The text has changed.';
}
</script>
What did I do wrong?
Your type attribute is wrong. You don't really need it at all. If you do want to include it, change it to text/javascript.

What is wrong here in this angularjs code [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Here is the code with ng-model and updating it from controller
Below is my dom element.
<div ng-app>
<div ng-controller="AppCtrl">
<input type="text" ng-model="guages" value="{{guages}}"/>
</div>
</div>
This is my controller, what is wrong in this.
function AppCtrl($scope){
console.log($scope.guages);
$scope.gauges=5;
}
You have guages v.s gauges in the sample.
$scope.gauges=5;
should be
$scope.guages=5

Find all inputs with special attribute name, where part of name is javascript variable [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
$("td[id^='td0_']")
My question is how can I replace 0 in the example above with a variable myvar?
You should be able to use:
$("td[id^='td" + myvar + "_']")
Use the quotes appropriately.
$("td[id^='td" + myvar +"_']")

Categories