jquery-1.6

Setting a control to readonly using jquery 1.6 .prop()

喜夏-厌秋 提交于 2019-11-29 09:05:13
With the release of jQuery 1.6, the recommendation on SO has been to generally start using prop() where you used to use attr(). What happens when I want make an element readonly? $('.control').prop('readonly', 'readonly'); $('.control').prop('readonly', true); Neither of these seem to make the control readonly. Is making an element readonly the exception to the rule? The problem is that the property name is case-sensitive. Try: $('.control').prop('readOnly', true); Though really I don't know why this requires jQuery. This works just as well: document.getElementsByClassName("control")[0]

Select link by text (exact match)

一世执手 提交于 2019-11-27 03:08:44
Using jQuery, I want to select a link that contains exactly some kind of text. For example: <p><a>This One</a></p> <p><a>"This One?"</a></p> <p><a>Unlikely</a></p> I have tried this: $('a:contains("This One")') But it picks the first AND the second link. I just want the first link, which contains exactly "This One". How can I do that? You can do this: $('a').filter(function(index) { return $(this).text() === "This One"; }); Reference: http://api.jquery.com/filter/ A coworker of mine extended jQuery with a function to do this: $.expr[':'].textEquals = function(a, i, m) { return $(a).text()

Select link by text (exact match)

微笑、不失礼 提交于 2019-11-26 10:27:22
问题 Using jQuery, I want to select a link that contains exactly some kind of text. For example: <p><a>This One</a></p> <p><a>\"This One?\"</a></p> <p><a>Unlikely</a></p> I have tried this: $(\'a:contains(\"This One\")\') But it picks the first AND the second link. I just want the first link, which contains exactly \"This One\". How can I do that? 回答1: You can do this: $('a').filter(function(index) { return $(this).text() === "This One"; }); Reference: http://api.jquery.com/filter/ 回答2: A coworker