Iframes and jQuery – Working with an iframe’s parent

Access parent windows within iframe using jQuery.

e.g.

<script type=”text/javascript”>

p=window.parent;

p.$(‘#select2’).append(‘<option value=\”$matches[1],$matches[2]\”>&lt; $matches[1] &gt; $matches[2]</option>’);

</script>

, ,

jQuery – get element by id, class, name

In jQuery, you can get elements with CSS class name and id easily.

For example,

1. ID: #id

  • $(‘#idA’) – selects all elements that have an id of ‘idA’, regardless of its tag name.
  • $(‘div#idA’) – selects all div elements that has an id of ‘idA’.

2. Class: .classname

  • $(‘.classA’) – selects all elements that have an class name of ‘classA’, regardless of its tag name.
  • $(‘div.classA’) – selects all div elements that has an class name of ‘classA’.

3. Class: [name=”value”]

  • $(‘div[name^=”nameA”]’) – selects all elements that have an name of ‘nameA’, regardless of its tag name.
  • e.g. [name*=”value”], [name~=”value”], [name$=”value”]

3. Change attr: $(‘#idA’).attr()

  • $(‘#idA’).attr(‘src’, ‘value) – change value of attribute that have an idof ‘idA’, regardless of its tag name.

Full Example

<html>
<head>
<title>jQuery Get element with class name and id</title>

<script type="text/javascript" src="jquery-1.3.2.min.js"></script>

</head>

<script type="text/javascript">

$(document).ready(function(){

    var $element = $('.classABC').html();
    alert($element);

    var $element = $('#idABC').html();
    alert($element);

});

</script>
<body>

<h1>jQuery Get element with class name and id</h1>

	<div class="classABC">
		This is belong to 'div' 
	</div>

	<div id="idABC">
		This is belong to 'div id="idABC"'
	</div>

</body>
</html>
http://www.mkyong.com/jquery/jquery-how-to-get-element-with-css-class-name-and-id/
,