Jump to content
php.lv forumi

jQuery: Pretējs


daGrevis

Recommended Posts

Sveiki,

Veidoju mazu jQ skriptiņu, kurš...

 

Visiem "a" tagiem, kuriem nav "title" atribūts pievieno to ar saturu, kāds ir starp attiecīgajiem tagiem.

 

$(function() {

$( 'a' && !'a[title]' )
	.each( function() {

		$( this ).attr( 'title', $( this ).text() )

	} );

} );

 

Problēma ir tieši ar to, ka nemāku definēt to, ka tiem kuriem nav "title" atribūts, jo jQ īsti nerunā Manā valodā. Ņēmu "!" kā no PHP, bet kaut kas "ģļučī"... xD

Link to comment
Share on other sites

var me = false;

jQuery("a:not([title])").each(function() { me = jQuery(this); me.attr('title', me.html()); });

 

Vienkaarshi shaadi...

 

Teoreetiski selektoram vajadzeetu sekot xPath sintaksei (http://en.wikipedia.org/wiki/XPath), tiesa jQuery gadiijumaa ne vienmeer taa ir...neesmu 100% droshs, bet pareizs xPath buutu 'a[not(@title)]'

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...