attr

Open all links in new tabs with jQuery

我只是一个虾纸丫 提交于 2019-12-01 03:14:38
I have some links that are placed in my page dynamically via JSON and have no way to directly edit them. I want to force all links to open in new tabs, ala target="_blank" Thought this would work.. but sadly it isn't. Any ideas? $('a').attr("target","_blank"); Here's a jsFiddle with the dynamic code: http://jsfiddle.net/danielredwood/mrgta/7/ You could do this (which lets the users browser decide whether to open a new window or tab) $('a').live('click', function() { window.open($(this).attr('href')); return false; }); Your problem might be one of timing. Keep in mind, when you call something

Should href be set with prop() or attr()? [duplicate]

孤人 提交于 2019-11-30 16:57:24
This question already has an answer here: How to change the href for a hyperlink using jQuery 11 answers .prop() vs .attr() 17 answers If I want to change the href of a link dynamically, should I do so using prop() or attr() ? You would use .attr() , as .prop() is more commonly used for boolean properties such as checked , selected , etc - though it is certainly possible with .prop it's arguably less clear as per your intent Though I do believe that ultimately they are very similar (or used to be) functionality-wise Just a note: the jQuery API site seems to follow the boolean 'sway': .prop() -

How do I check for empty attr() in jquery?

China☆狼群 提交于 2019-11-30 12:45:13
I have a few divs that are created using PHP. The anchor within the div always has a HREF, even if it is blank. Basically, I am trying to detect if the HREF is blank. If it has content, do nothing, if it's blank, strip the text out, delete the anchor, them put the text back in. Here is the div: <div class="title"> <a class="article" href="">Lorem Ipsum</a> </div> Here is my code: jQuery(document).ready(function($) { //required for $ to work in Wordpress $(".article").each(function(){ if ($(this).attr('href') !== undefined) { return; } else { var linkTitle = $(this).html(); $(this).parent()

delay() and fadeOut() don't delay attr() in the queue

强颜欢笑 提交于 2019-11-30 09:12:54
what is wrong in this code? I'm trying to get this effect: fadeOut(500) and attr('class','myClass') delayed by 600 millisecs.. then delay(600) again, and fadeIn(500) . The delays happen correctly but the attr() is not being delayed, it fires when #myDiv is still fading! :'( $('#myDiv').fadeOut(500) .delay(600) .attr('class','myClass') .delay(600) .fadeIn(500); The .delay() only affects the animation or fx queue (unless you specify a different queue specifically). Keep in mind that chaining and queuing are 2 distinctly different concepts, chaining continues the use of the same jquery set, but

How do I set an attr_accessor for a dynamic instance variable?

喜你入骨 提交于 2019-11-29 20:56:49
I dynamically created an instance variable within my class: class Mine attr_accessor :some_var def intialize @some_var = true end def my_number num self.instance_variable_set "@my_#{num}", num end end How do I make @my_#{num} now as an attr value? e.g. I want to be able to do this: dude = Mine.new dude.my_number 1 dude.my_1 => 1 this answer doesn't pollutes the class space, example.. if i do mine.my_number 4 then the other instances of Mine will not get the my_4 method.. this happens because we use the singleton class of the object instead of the class. class Mine def my_number num singleton

How do I check for empty attr() in jquery?

风流意气都作罢 提交于 2019-11-29 17:50:49
问题 I have a few divs that are created using PHP. The anchor within the div always has a HREF, even if it is blank. Basically, I am trying to detect if the HREF is blank. If it has content, do nothing, if it's blank, strip the text out, delete the anchor, them put the text back in. Here is the div: <div class="title"> <a class="article" href="">Lorem Ipsum</a> </div> Here is my code: jQuery(document).ready(function($) { //required for $ to work in Wordpress $(".article").each(function(){ if ($

Read nose tests arguments in a file especially @attr

穿精又带淫゛_ 提交于 2019-11-29 11:57:14
If I invoke a test script say nosetests -a tag1='one' is there a way to print the user input of tag1 in my script? @attr(tag1=['one', 'two', 'three', 'four']) def test_real_logic(self): #how to print the user input here Not without some pain. self.test_real_logic.tag1 should give you all the attributes attached to the function. They are stored as a dictionary within __dict__ attribute of the test function. For test_real_logic.tag1 it would be ['one', 'two', 'three', 'four']. If you do not want to hard code function name, you cad try extract the dictionary by doing something like: import sys

JS .checked vs jquery attr('checked'), what is the difference?

一笑奈何 提交于 2019-11-29 09:57:27
I can't figure this one out. According to W3 Schools , the checked property sets or returns the checked state of a checkbox. So why does $('input').checked ? $('div').slideDown() : $('div').slideUp(); not work? Using prop however, does work. $('input').prop('checked') ? $('div').slideDown() : $('div').slideUp(); This is for a checkbox that is checked based on a database value. checked is a DOM element property so use it on DOM elements instead of jQuery objects. $('input')[0].checked if you have a jQuery object, use prop instead of attr since you are checking a property. Just as a reference: $

get href attribute of enclosing link tag

两盒软妹~` 提交于 2019-11-29 08:04:12
Having a little trouble on this one. I need a way using Jquery/JS to find the HREF attribute of the enclosing link tag: <a href="something.html"><img src="img1.jpg" class="active"></a> I want to target the img by class and find the value of the 1st preceding href attribute. $("img.active").somethingAwesome().attr("href"); Please show me somethingAwesome() ...help? $("img.active").parent("a").attr("href") will get the direct parent's href attribute, assuming it's an anchor. If there's any depth of containing blocks between the image and the anchor, use instead $("img.active").closest("a").attr(

Alternative for jQuery attr() in IE?

岁酱吖の 提交于 2019-11-29 04:21:19
Ok, correct me if I'm wrong, but I take it that jQuery attr() does NOT work in IE. ( marked wontfix ) That being the case, what is the best alternative? For example, this works everywhere but IE: jQuery(document).ready(function($) { $('.airsrc').each(function() { var $this = $(this); var src = $this.attr('data-websrc'); $this.attr('src', src); }); }); Update: Whoops...I realize the issue. I actually had this inside an if statement based on a CSS3 media query. Media queries that aren't natively supported in IE8 or lower. The attr() definitely works! I use attr with data-* attributes on IE all