2

I have some code as below

<div class="box coursebox">
  <h3 class="main"><a title="GCSE English" href="http://vle.sheffcol.ac.uk/moodle/course/view.php?id=1656">GCSE English</a> </h3>
</div>
<div class="box coursebox">
  <h3 class="main"> <a title="GCSE Maths" href="http://vle.sheffcol.ac.uk/moodle/course/view.php?id=1526">GCSE Maths</a> </h3>
  <div class="assign overview">
     <div class="name"> Assignment: <a title="Assignment" href="http://vle.sheffcol.ac.uk/moodle/mod/assign/view.php?id=59691">Algebra assignment 1</a> </div>
     <div class="name"> Assignment: <a title="Assignment" href="http://vle.sheffcol.ac.uk/moodle/mod/assign/view.php?id=59691">Algebra assignment 1</a> </div>
  </div>
</div>

What I want to do it use jquery to add the following bit of HTML

<span class="button" id="button">Show activities</span>

to each coursebox after the H3 tag IF there is a div.overview as a child.

Firstly, is this possible, and if so how?

Thanks

Kieran

3 Answers 3

4

Yes it's possible, try this:

$(".coursebox").has("div.overview").each(function() {
    $("h3", $(this)).after("<span class=\"button\" id=\"button\">Show activities</span>");
});

Example fiddle

Sign up to request clarification or add additional context in comments.

Comments

0

Try this solution

$(".coursebox").has("div.overview").each(function(){
  var $span = $("<span>")
      .addClass('button')
      .attr('id','button')
      .text('Show activities');

    $span.insertAfter($(this).find('H3.main'))

});​​​​​​​

Comments

0
var spanEl = $('<span/>', {
 id: "button",
 class: "button",
 text: "Show activities"
});
$("h3", $(this)).after(spanEl);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.