attr

jQuery - How to select value by attribute name starts with

坚强是说给别人听的谎言 提交于 2019-11-26 12:19:41
问题 I want to select attribute value by giving attribute name (only starts with) For instance if we have html tag <div class = \"slide\" data-confirmID = \"46\" confirmID = \"54\"/> I want to select the value from the attribute starts with data- Thanks in advance for the help. 回答1: If you want all data-* attributes, you can iterate through jq data object: $('.slide').each(function(){ for(data in $(this).data()) console.log(data); // returns confirmID so element as an attribute `data-confirmID` })

Css Content, Attr and Url in the same sentence

断了今生、忘了曾经 提交于 2019-11-26 11:36:08
问题 I have used the content attribute for a long time, and today I wanted to try something new. Instead of using JS to display a image tooltip I wanted to know if it was possible to do it dynamically with CSS. So I tried: .TableLine:hover:after{ content: url(\"../Img/Photo/\"attr(id)\".jpg\"); } where attr(id) is supposed to return the ID of the picture (alphanumeric) which is also the name of the picture. It doesn\'t work at all, it has no effect. I think that the block did not parse because

difference between prop() and attr() in jQuery and when to use attr() and prop() [duplicate]

六眼飞鱼酱① 提交于 2019-11-26 11:19:58
This question already has an answer here: .prop() vs .attr() 17 answers I saw in some places .attr() is used in jQuery.In some places .prop() is used.But i searched in SO and google i am very confused .Please tell me the exact difference between these two and when to use them. I have seen the following links jQuery attr vs. prop, there are a list of props? jQuery attr vs prop? But I did not got the answer.Please help me.Thanks in advance. Before giving a downvote please explain the reason, then I will correct in my next post. from docs The difference between attributes and properties can be

jQuery .attr(“disabled”, “disabled”) not working in Chrome

﹥>﹥吖頭↗ 提交于 2019-11-26 06:39:18
问题 Not sure why this isn\'t working. When people click the \'edit\' button of my application, the disabled textfields become editable: $(\"#bewerken\").click(function(e) { $(\"input[disabled=\'disabled\']\").removeAttr(\'disabled\'); }); I then want to disable the textfields again when the user saves; I have this code bound to my save button: $(\"#save_school_changes\").click(function(e) { //stuff $.ajax({ type: \"POST\", url: \"/school/save_changes\", data: { //stuff }, success: function(data)

CSS set background-image by data-image attr

本小妞迷上赌 提交于 2019-11-26 04:49:10
问题 I have sort of elements with this pattern: <div data-image=\"{imageurl}\" ...></div> I want to set this elements background-image to data-image . I test this CSS code: div[data-image] { border: 2px solid black; background-image: attr(data-image url); } border show correctly but nothing happened for background How can do I fix this code only with css (not js or jq)? 回答1: As of writing, the browser support of attr() notation on CSS properties other than content - like background-image - is very

Toggle input disabled attribute using jQuery

折月煮酒 提交于 2019-11-26 03:48:12
问题 Here is my code: $(\"#product1 :checkbox\").click(function(){ $(this) .closest(\'tr\') // Find the parent row. .find(\":input[type=\'text\']\") // Find text elements in that row. .attr(\'disabled\',false).toggleClass(\'disabled\') // Enable them. .end() // Go back to the row. .siblings() // Get its siblings .find(\":input[type=\'text\']\") // Find text elements in those rows. .attr(\'disabled\',true).removeClass(\'disabled\'); // Disable them. }); How do I toggle .attr(\'disabled\',false); ?

jQuery attr vs prop?

你。 提交于 2019-11-26 03:38:15
问题 Now this isn\'t just another What\'s the difference question , I have done some tests(http://jsfiddle.net/ZC3Lf/) modifying the prop and attr of <form action=\"/test/\"></form>​ with the output being: 1) prop Modification test Prop: http://fiddle.jshell.net/test/1 Attr: http://fiddle.jshell.net/test/1 2) Attr Modification test Prop: http://fiddle.jshell.net/test/1 Attr: /test/1 3) Attr then Prop Modification test Prop: http://fiddle.jshell.net/test/11 Attr: http://fiddle.jshell.net/test/11 4)

How to change href of <a> tag on button click through javascript

二次信任 提交于 2019-11-26 00:48:00
问题 How to change the href attribute value of an <a/> tag through Javascript on button click ? <script type=\"text/javascript\"> function f1() { document.getElementById(\"abc\").href=\"xyz.php\"; } </script> <a href=\"\" id=\"abc\">jhg</a> <a href=\"\" id=\"\" onclick=\"f1()\">jhhghj</a> 回答1: Without having a href , the click will reload the current page, so you need something like this: <a href="#" onclick="f1()">jhhghj</a> Or prevent the scroll like this: <a href="#" onclick="f1(); return false

.prop() vs .attr()

二次信任 提交于 2019-11-25 22:10:18
问题 So jQuery 1.6 has the new function prop(). $(selector).click(function(){ //instead of: this.getAttribute(\'style\'); //do i use: $(this).prop(\'style\'); //or: $(this).attr(\'style\'); }) or in this case do they do the same thing? And if I do have to switch to using prop() , all the old attr() calls will break if i switch to 1.6? UPDATE selector = \'#id\' $(selector).click(function() { //instead of: var getAtt = this.getAttribute(\'style\'); //do i use: var thisProp = $(this).prop(\'style\');

How to change href of <a> tag on button click through javascript

点点圈 提交于 2019-11-25 19:23:32
How to change the href attribute value of an <a/> tag through Javascript on button click ? <script type="text/javascript"> function f1() { document.getElementById("abc").href="xyz.php"; } </script> <a href="" id="abc">jhg</a> <a href="" id="" onclick="f1()">jhhghj</a> Without having a href , the click will reload the current page, so you need something like this: <a href="#" onclick="f1()">jhhghj</a> Or prevent the scroll like this: <a href="#" onclick="f1(); return false;">jhhghj</a> Or return false in your f1 function and: <a href="#" onclick="return f1();">jhhghj</a> ....or, the unobtrusive